Remove _list & Fix moveImage bug

This commit is contained in:
ckcz123 2018-12-23 14:42:07 +08:00
parent 388d8de160
commit e388abfaa7
5 changed files with 36 additions and 66 deletions

View File

@ -543,10 +543,6 @@ zIndex为创建的纵向高度关系到画布之间的覆盖z值高的
返回创建的画布的context也可以通过core.dymCanvas[name]调用。
core.ui.findCanvas(name)
寻找一个自定义画布的索引;如果存在该画布则返回对应的索引,不存在画布则返回-1。
core.ui.relocateCanvas(name, x, y)
重新定位一个自定义画布。

View File

@ -3169,11 +3169,11 @@ control.prototype.domRenderer = function(){
});
}
// 动态canvas
for (var i = 0; i < core.dymCanvas._list.length; i++) {
var spirit = core.dymCanvas._list[i];
core.dymCanvas[spirit.id].canvas.style.width = core.dymCanvas[spirit.id].canvas.width * core.domStyle.scale + "px";
core.dymCanvas[spirit.id].canvas.style.height = core.dymCanvas[spirit.id].canvas.height * core.domStyle.scale + "px";
core.dymCanvas[spirit.id].canvas.style.left = spirit.style.left * core.domStyle.scale + "px";
core.dymCanvas[spirit.id].canvas.style.top = spirit.style.top * core.domStyle.scale + "px"
for (var name in core.dymCanvas) {
var ctx = core.dymCanvas[name], canvas = ctx.canvas;
canvas.style.width = canvas.width * core.domStyle.scale + "px";
canvas.style.height = canvas.height * core.domStyle.scale + "px";
canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle + "px";
canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle + "px";
}
}

View File

@ -192,9 +192,7 @@ function core() {
'animateObjs': [],
};
this.status = {};
this.dymCanvas = {
"_list": []
};
this.dymCanvas = {};
}
/////////// 系统事件相关 ///////////
@ -734,11 +732,6 @@ core.prototype.createCanvas = function (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重定位 //////
core.prototype.relocateCanvas = function (name, x, y) {
return core.ui.relocateCanvas(name, x, y);

View File

@ -1573,7 +1573,6 @@ events.prototype.hideImage = function (code, time, callback) {
time = time || 0;
var name = "image"+ (code+100);
if (!core.isset(core.dymCanvas[name])) {
console.log(code+"号图片不存在")
if (core.isset(callback)) callback();
return;
}
@ -1635,19 +1634,20 @@ events.prototype.textImage = function (content) {
events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
time = time || 1000;
var name = "image"+ (code+100), index = core.findCanvas(name);
if (index == -1) {
console.log(code+"号图片不存在")
var name = "image"+ (code+100);
if (!core.isset(core.dymCanvas[name])) {
if (core.isset(callback)) callback();
return;
}
var fromX = core.dymCanvas._list[index].style.left,
fromY = core.dymCanvas._list[index].style.top,
var fromX = parseFloat(core.dymCanvas[name].canvas.getAttribute("_left")),
fromY = parseFloat(core.dymCanvas[name].canvas.getAttribute("_top")),
preX = fromX, preY = fromY, toX = fromX, toY = fromY;
if (core.isset(to)) {
toX = core.calValue(to[0]) || toX;
toY = core.calValue(to[1]) || toY;
toX = core.calValue(to[0]);
toY = core.calValue(to[1]);
if (!core.isset(toX)) toX = fromX;
if (!core.isset(toY)) toY = fromY;
}
var step = 0;

View File

@ -2845,8 +2845,7 @@ ui.prototype.drawHelp = function () {
////// canvas创建 //////
ui.prototype.createCanvas = function (name, x, y, width, height, z) {
// 如果画布已存在则直接调用
var cv = this.findCanvas(name);
if (cv!=-1) {
if (core.isset(core.dymCanvas[name])) {
this.relocateCanvas(name, x, y);
this.resizeCanvas(name, width, height);
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.width = width;
newCanvas.height = height;
newCanvas.setAttribute("_left", x);
newCanvas.setAttribute("_top", y);
newCanvas.style.width = width * core.domStyle.scale + 'px';
newCanvas.style.height = height * 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.position = 'absolute';
core.dymCanvas[name] = newCanvas.getContext('2d');
core.dymCanvas._list.push({
"id": name,
"style": {
"left": x,
"top": y,
}
});
core.dom.gameDraw.appendChild(newCanvas);
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重定位 //////
ui.prototype.relocateCanvas = function (name, x, y) {
var index = this.findCanvas(name);
if (index<0) return null;
var ctx = core.dymCanvas[name];
if (!core.isset(ctx)) return null;
if (core.isset(x)) {
core.dymCanvas[name].canvas.style.left = x * core.domStyle.scale + 'px';
core.dymCanvas._list[index].style.left = x;
ctx.canvas.style.left = x * core.domStyle.scale + 'px';
ctx.canvas.setAttribute("_left", x);
}
if (core.isset(y)) {
core.dymCanvas[name].canvas.style.top = y * core.domStyle.scale + 'px';
core.dymCanvas._list[index].style.top = y;
ctx.canvas.style.top = y * core.domStyle.scale + 'px';
ctx.canvas.setAttribute("_top", y);
}
return core.dymCanvas[name];
return ctx;
}
////// canvas重置 //////
ui.prototype.resizeCanvas = function (name, width, height) {
if (this.findCanvas(name)<0) return null;
var dstCanvas = core.dymCanvas[name].canvas;
var ctx = core.dymCanvas[name];
if (!core.isset(ctx)) return null;
if (core.isset(width)) {
dstCanvas.width = width;
dstCanvas.style.width = width * core.domStyle.scale + 'px';
ctx.canvas.width = width;
ctx.canvas.style.width = width * core.domStyle.scale + 'px';
}
if (core.isset(height)) {
dstCanvas.height = height;
dstCanvas.style.height = height * core.domStyle.scale + 'px';
ctx.canvas.height = height;
ctx.canvas.style.height = height * core.domStyle.scale + 'px';
}
return core.dymCanvas[name];
return ctx;
}
////// canvas删除 //////
ui.prototype.deleteCanvas = function (name) {
var index = this.findCanvas(name);
if (index<0) return null;
if (!core.isset(core.dymCanvas[name])) return null;
core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas);
delete core.dymCanvas[name];
core.dymCanvas._list.splice(index,1);
}
////// 删除所有动态canvas //////
ui.prototype.deleteAllCanvas = function () {
core.dymCanvas._list.forEach(function (t) {
core.dom.gameDraw.removeChild(core.dymCanvas[t.id].canvas);
delete core.dymCanvas[t.id];
Object.keys(core.dymCanvas).forEach(function (name) {
core.dom.gameDraw.removeChild(core.dymCanvas[name].canvas);
delete core.dymCanvas[name];
});
core.dymCanvas._list = [];
}