Merge pull request #290 from ckcz123/v2.0
Remove _list & Fix moveImage bug
This commit is contained in:
commit
98574ba162
@ -543,10 +543,6 @@ zIndex为创建的纵向高度(关系到画布之间的覆盖),z值高的
|
|||||||
返回创建的画布的context,也可以通过core.dymCanvas[name]调用。
|
返回创建的画布的context,也可以通过core.dymCanvas[name]调用。
|
||||||
|
|
||||||
|
|
||||||
core.ui.findCanvas(name)
|
|
||||||
寻找一个自定义画布的索引;如果存在该画布则返回对应的索引,不存在画布则返回-1。
|
|
||||||
|
|
||||||
|
|
||||||
core.ui.relocateCanvas(name, x, y)
|
core.ui.relocateCanvas(name, x, y)
|
||||||
重新定位一个自定义画布。
|
重新定位一个自定义画布。
|
||||||
|
|
||||||
|
|||||||
@ -3169,11 +3169,11 @@ control.prototype.domRenderer = function(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 动态canvas
|
// 动态canvas
|
||||||
for (var i = 0; i < core.dymCanvas._list.length; i++) {
|
for (var name in core.dymCanvas) {
|
||||||
var spirit = core.dymCanvas._list[i];
|
var ctx = core.dymCanvas[name], canvas = ctx.canvas;
|
||||||
core.dymCanvas[spirit.id].canvas.style.width = core.dymCanvas[spirit.id].canvas.width * core.domStyle.scale + "px";
|
canvas.style.width = canvas.width * core.domStyle.scale + "px";
|
||||||
core.dymCanvas[spirit.id].canvas.style.height = core.dymCanvas[spirit.id].canvas.height * core.domStyle.scale + "px";
|
canvas.style.height = canvas.height * core.domStyle.scale + "px";
|
||||||
core.dymCanvas[spirit.id].canvas.style.left = spirit.style.left * core.domStyle.scale + "px";
|
canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle + "px";
|
||||||
core.dymCanvas[spirit.id].canvas.style.top = spirit.style.top * core.domStyle.scale + "px"
|
canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle + "px";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,9 +192,7 @@ function core() {
|
|||||||
'animateObjs': [],
|
'animateObjs': [],
|
||||||
};
|
};
|
||||||
this.status = {};
|
this.status = {};
|
||||||
this.dymCanvas = {
|
this.dymCanvas = {};
|
||||||
"_list": []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////// 系统事件相关 ///////////
|
/////////// 系统事件相关 ///////////
|
||||||
@ -734,11 +732,6 @@ core.prototype.createCanvas = function (name, x, y, width, height, z) {
|
|||||||
return core.ui.createCanvas(name, x, y, width, height, z);
|
return core.ui.createCanvas(name, x, y, width, height, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
////// canvas查找 //////
|
|
||||||
core.prototype.findCanvas = function (name) {
|
|
||||||
return core.ui.findCanvas(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
////// canvas重定位 //////
|
////// canvas重定位 //////
|
||||||
core.prototype.relocateCanvas = function (name, x, y) {
|
core.prototype.relocateCanvas = function (name, x, y) {
|
||||||
return core.ui.relocateCanvas(name, x, y);
|
return core.ui.relocateCanvas(name, x, y);
|
||||||
|
|||||||
@ -1573,7 +1573,6 @@ events.prototype.hideImage = function (code, time, callback) {
|
|||||||
time = time || 0;
|
time = time || 0;
|
||||||
var name = "image"+ (code+100);
|
var name = "image"+ (code+100);
|
||||||
if (!core.isset(core.dymCanvas[name])) {
|
if (!core.isset(core.dymCanvas[name])) {
|
||||||
console.log(code+"号图片不存在")
|
|
||||||
if (core.isset(callback)) callback();
|
if (core.isset(callback)) callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1635,19 +1634,20 @@ events.prototype.textImage = function (content) {
|
|||||||
events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
|
events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
|
||||||
time = time || 1000;
|
time = time || 1000;
|
||||||
|
|
||||||
var name = "image"+ (code+100), index = core.findCanvas(name);
|
var name = "image"+ (code+100);
|
||||||
if (index == -1) {
|
if (!core.isset(core.dymCanvas[name])) {
|
||||||
console.log(code+"号图片不存在")
|
|
||||||
if (core.isset(callback)) callback();
|
if (core.isset(callback)) callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var fromX = core.dymCanvas._list[index].style.left,
|
var fromX = parseFloat(core.dymCanvas[name].canvas.getAttribute("_left")),
|
||||||
fromY = core.dymCanvas._list[index].style.top,
|
fromY = parseFloat(core.dymCanvas[name].canvas.getAttribute("_top")),
|
||||||
preX = fromX, preY = fromY, toX = fromX, toY = fromY;
|
preX = fromX, preY = fromY, toX = fromX, toY = fromY;
|
||||||
|
|
||||||
if (core.isset(to)) {
|
if (core.isset(to)) {
|
||||||
toX = core.calValue(to[0]) || toX;
|
toX = core.calValue(to[0]);
|
||||||
toY = core.calValue(to[1]) || toY;
|
toY = core.calValue(to[1]);
|
||||||
|
if (!core.isset(toX)) toX = fromX;
|
||||||
|
if (!core.isset(toY)) toY = fromY;
|
||||||
}
|
}
|
||||||
|
|
||||||
var step = 0;
|
var step = 0;
|
||||||
|
|||||||
61
libs/ui.js
61
libs/ui.js
@ -2845,8 +2845,7 @@ ui.prototype.drawHelp = function () {
|
|||||||
////// canvas创建 //////
|
////// canvas创建 //////
|
||||||
ui.prototype.createCanvas = function (name, x, y, width, height, z) {
|
ui.prototype.createCanvas = function (name, x, y, width, height, z) {
|
||||||
// 如果画布已存在则直接调用
|
// 如果画布已存在则直接调用
|
||||||
var cv = this.findCanvas(name);
|
if (core.isset(core.dymCanvas[name])) {
|
||||||
if (cv!=-1) {
|
|
||||||
this.relocateCanvas(name, x, y);
|
this.relocateCanvas(name, x, y);
|
||||||
this.resizeCanvas(name, width, height);
|
this.resizeCanvas(name, width, height);
|
||||||
core.dymCanvas[name].canvas.style.zIndex = z;
|
core.dymCanvas[name].canvas.style.zIndex = z;
|
||||||
@ -2857,6 +2856,8 @@ ui.prototype.createCanvas = function (name, x, y, width, height, z) {
|
|||||||
newCanvas.style.display = 'block';
|
newCanvas.style.display = 'block';
|
||||||
newCanvas.width = width;
|
newCanvas.width = width;
|
||||||
newCanvas.height = height;
|
newCanvas.height = height;
|
||||||
|
newCanvas.setAttribute("_left", x);
|
||||||
|
newCanvas.setAttribute("_top", y);
|
||||||
newCanvas.style.width = width * core.domStyle.scale + 'px';
|
newCanvas.style.width = width * core.domStyle.scale + 'px';
|
||||||
newCanvas.style.height = height * core.domStyle.scale + 'px';
|
newCanvas.style.height = height * core.domStyle.scale + 'px';
|
||||||
newCanvas.style.left = x * core.domStyle.scale + 'px';
|
newCanvas.style.left = x * core.domStyle.scale + 'px';
|
||||||
@ -2864,70 +2865,50 @@ ui.prototype.createCanvas = function (name, x, y, width, height, z) {
|
|||||||
newCanvas.style.zIndex = z;
|
newCanvas.style.zIndex = z;
|
||||||
newCanvas.style.position = 'absolute';
|
newCanvas.style.position = 'absolute';
|
||||||
core.dymCanvas[name] = newCanvas.getContext('2d');
|
core.dymCanvas[name] = newCanvas.getContext('2d');
|
||||||
core.dymCanvas._list.push({
|
|
||||||
"id": name,
|
|
||||||
"style": {
|
|
||||||
"left": x,
|
|
||||||
"top": y,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
core.dom.gameDraw.appendChild(newCanvas);
|
core.dom.gameDraw.appendChild(newCanvas);
|
||||||
return core.dymCanvas[name];
|
return core.dymCanvas[name];
|
||||||
}
|
}
|
||||||
|
|
||||||
////// canvas查找 //////
|
|
||||||
ui.prototype.findCanvas = function (name) {
|
|
||||||
if (!core.isset(name)) return -1;
|
|
||||||
for (var index = 0; index < core.dymCanvas._list.length; index++) {
|
|
||||||
if (core.dymCanvas._list[index].id == name)
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
////// canvas重定位 //////
|
////// canvas重定位 //////
|
||||||
ui.prototype.relocateCanvas = function (name, x, y) {
|
ui.prototype.relocateCanvas = function (name, x, y) {
|
||||||
var index = this.findCanvas(name);
|
var ctx = core.dymCanvas[name];
|
||||||
if (index<0) return null;
|
if (!core.isset(ctx)) return null;
|
||||||
if (core.isset(x)) {
|
if (core.isset(x)) {
|
||||||
core.dymCanvas[name].canvas.style.left = x * core.domStyle.scale + 'px';
|
ctx.canvas.style.left = x * core.domStyle.scale + 'px';
|
||||||
core.dymCanvas._list[index].style.left = x;
|
ctx.canvas.setAttribute("_left", x);
|
||||||
}
|
}
|
||||||
if (core.isset(y)) {
|
if (core.isset(y)) {
|
||||||
core.dymCanvas[name].canvas.style.top = y * core.domStyle.scale + 'px';
|
ctx.canvas.style.top = y * core.domStyle.scale + 'px';
|
||||||
core.dymCanvas._list[index].style.top = y;
|
ctx.canvas.setAttribute("_top", y);
|
||||||
}
|
}
|
||||||
return core.dymCanvas[name];
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
////// canvas重置 //////
|
////// canvas重置 //////
|
||||||
ui.prototype.resizeCanvas = function (name, width, height) {
|
ui.prototype.resizeCanvas = function (name, width, height) {
|
||||||
if (this.findCanvas(name)<0) return null;
|
var ctx = core.dymCanvas[name];
|
||||||
var dstCanvas = core.dymCanvas[name].canvas;
|
if (!core.isset(ctx)) return null;
|
||||||
if (core.isset(width)) {
|
if (core.isset(width)) {
|
||||||
dstCanvas.width = width;
|
ctx.canvas.width = width;
|
||||||
dstCanvas.style.width = width * core.domStyle.scale + 'px';
|
ctx.canvas.style.width = width * core.domStyle.scale + 'px';
|
||||||
}
|
}
|
||||||
if (core.isset(height)) {
|
if (core.isset(height)) {
|
||||||
dstCanvas.height = height;
|
ctx.canvas.height = height;
|
||||||
dstCanvas.style.height = height * core.domStyle.scale + 'px';
|
ctx.canvas.style.height = height * core.domStyle.scale + 'px';
|
||||||
}
|
}
|
||||||
return core.dymCanvas[name];
|
return ctx;
|
||||||
}
|
}
|
||||||
////// canvas删除 //////
|
////// canvas删除 //////
|
||||||
ui.prototype.deleteCanvas = function (name) {
|
ui.prototype.deleteCanvas = function (name) {
|
||||||
var index = this.findCanvas(name);
|
if (!core.isset(core.dymCanvas[name])) return null;
|
||||||
if (index<0) return null;
|
|
||||||
core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas);
|
core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas);
|
||||||
delete core.dymCanvas[name];
|
delete core.dymCanvas[name];
|
||||||
core.dymCanvas._list.splice(index,1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 删除所有动态canvas //////
|
////// 删除所有动态canvas //////
|
||||||
ui.prototype.deleteAllCanvas = function () {
|
ui.prototype.deleteAllCanvas = function () {
|
||||||
core.dymCanvas._list.forEach(function (t) {
|
Object.keys(core.dymCanvas).forEach(function (name) {
|
||||||
core.dom.gameDraw.removeChild(core.dymCanvas[t.id].canvas);
|
core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas);
|
||||||
delete core.dymCanvas[t.id];
|
delete core.dymCanvas[name];
|
||||||
});
|
});
|
||||||
core.dymCanvas._list = [];
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user