图块和视角变速移动

This commit is contained in:
ckcz123 committed 2021-07-26 18:16:24 +08:00
1 parent 2ae21a0bca
commit a6d74c00aa
9 files changed
+80 -37

No files matched your search

+10 -8
View File
@@ -968,23 +968,25 @@ control.prototype.setViewport = function (px, py) {
}
////// 移动视野范围 //////
control.prototype.moveViewport = function (x, y, time, callback) {
control.prototype.moveViewport = function (x, y, moveMode, time, callback) {
time = time || 0;
time /= Math.max(core.status.replay.speed, 1)
var per_time = 10, step = parseInt(time / per_time);
if (step <= 0) {
var per_time = 10, step = 0, steps = parseInt(time / per_time);
if (steps <= 0) {
this.setViewport(32 * x, 32 * y);
if (callback) callback();
return;
}
}
var px = core.clamp(32 * x, 0, 32 * core.bigmap.width - core.__PIXELS__);
var py = core.clamp(32 * y, 0, 32 * core.bigmap.height - core.__PIXELS__);
var dx = (px - core.bigmap.offsetX) / step, dy = (py - core.bigmap.offsetY) / step;
var cx = core.bigmap.offsetX;
var cy = core.bigmap.offsetY;
var moveFunc = core.applyEasing(moveMode);
var animate=window.setInterval(function() {
core.setViewport(core.bigmap.offsetX + dx, core.bigmap.offsetY + dy);
step--;
if (step <= 0) {
step++;
core.setViewport(cx + moveFunc(step / steps) * (px - cx), cy + moveFunc(step / steps) * (py - cy));
if (step == steps) {
delete core.animateFrame.asyncId[animate];
clearInterval(animate);
core.setViewport(px, py);
+10 -9
View File
@@ -1449,7 +1449,7 @@ events.prototype._action_setViewport = function (data, x, y, prefix) {
data.loc = this.__action_getLoc(data.loc, x, y, prefix);
}
console.log(data.loc);
this.__action_doAsyncFunc(data.async, core.moveViewport, data.loc[0], data.loc[1], data.time);
this.__action_doAsyncFunc(data.async, core.moveViewport, data.loc[0], data.loc[1], data.moveMode, data.time);
}
events.prototype._action_move = function (data, x, y, prefix) {
@@ -1567,7 +1567,7 @@ events.prototype._action_showGif = function (data, x, y, prefix) {
events.prototype._action_moveImage = function (data, x, y, prefix) {
if (this.__action_checkReplaying()) return;
this.__action_doAsyncFunc(data.async, core.moveImage, data.code, data.to, data.opacity, data.time);
this.__action_doAsyncFunc(data.async, core.moveImage, data.code, data.to, data.opacity, data.moveMode, data.time);
}
events.prototype._precompile_moveImage = function (data) {
@@ -2988,7 +2988,7 @@ events.prototype.showImage = function (code, image, sloc, loc, opacityVal, time,
return;
}
core.setOpacity(name, 0);
this.moveImage(code, null, opacityVal, time, callback);
this.moveImage(code, null, opacityVal, null, time, callback);
}
////// 隐藏图片 //////
@@ -3000,14 +3000,14 @@ events.prototype.hideImage = function (code, time, callback) {
if (callback) callback();
return;
}
this.moveImage(code, null, 0, time, function () {
this.moveImage(code, null, 0, null, time, function () {
core.deleteCanvas(name);
if (callback) callback();
});
}
////// 移动图片 //////
events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
events.prototype.moveImage = function (code, to, opacityVal, moveMode, time, callback) {
time = time || 1000;
to = to || [];
var name = "image" + (code + 100);
@@ -3028,21 +3028,22 @@ events.prototype.moveImage = function (code, to, opacityVal, time, callback) {
this._moveImage_moving(name, {
fromX: fromX, fromY: fromY, toX: toX, toY: toY, opacity: opacity, toOpacity: toOpacity,
time: time / Math.max(core.status.replay.speed, 1)
moveMode: moveMode, time: time / Math.max(core.status.replay.speed, 1)
}, callback)
}
events.prototype._moveImage_moving = function (name, moveInfo, callback) {
var per_time = 10, step = 0, steps = parseInt(moveInfo.time / 10);
var per_time = 10, step = 0, steps = parseInt(moveInfo.time / per_time);
if (steps <= 0) steps = 1;
var fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY,
opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity;
var currX = fromX, currY = fromY, currOpacity = opacity;
var moveFunc = core.applyEasing(moveInfo.moveMode);
var animate = setInterval(function () {
step++;
currOpacity = opacity + (toOpacity - opacity) * step / steps;
currX = parseInt(fromX + (toX - fromX) * step / steps);
currY = parseInt(fromY + (toY - fromY) * step / steps);
currX = parseInt(fromX + (toX - fromX) * moveFunc(step / steps));
currY = parseInt(fromY + (toY - fromY) * moveFunc(step / steps));
core.setOpacity(name, currOpacity);
core.relocateCanvas(name, currX, currY);
if (step == steps) {
+21
View File
@@ -480,6 +480,27 @@ utils.prototype.formatBigNumber = function (x, onMap) {
return c + x;
}
////// 变速移动 //////
utils.prototype.applyEasing = function(name) {
var list = {
"easeIn": function(t) {
return Math.pow(t, 3);
},
"easeOut": function(t) {
return 1 - Math.pow(1 - t, 3);
},
"easeInOut": function(t) {
// easeInOut试了一下感觉二次方效果明显点
if (t < 0.5) return Math.pow(t, 2) * 2;
else return 1 - Math.pow(1 - t, 2) * 2;
},
"linear": function(t) {
return t
}
}
return list[name] || list.linear;
}
////// 数组转RGB //////
utils.prototype.arrayToRGB = function (color) {
if (!(color instanceof Array)) return color;