Fix animate async
This commit is contained in:
parent
e822543bf1
commit
3b1c8b8a80
@ -717,7 +717,7 @@ actions.prototype._sys_keyDownCtrl = function () {
|
||||
}
|
||||
if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep'
|
||||
&& !core.status.event.data.current.noSkip) {
|
||||
if (core.timeout.sleepTimeout && Object.keys(core.animateFrame.asyncId).length == 0) {
|
||||
if (core.timeout.sleepTimeout && !core.hasAsync()) {
|
||||
clearTimeout(core.timeout.sleepTimeout);
|
||||
core.timeout.sleepTimeout = null;
|
||||
core.doAction();
|
||||
@ -752,7 +752,7 @@ actions.prototype._sys_longClick_lockControl = function (x, y) {
|
||||
// 长按可以跳过等待事件
|
||||
if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep'
|
||||
&& !core.status.event.data.current.noSkip) {
|
||||
if (core.timeout.sleepTimeout && Object.keys(core.animateFrame.asyncId).length == 0) {
|
||||
if (core.timeout.sleepTimeout && !core.hasAsync()) {
|
||||
clearTimeout(core.timeout.sleepTimeout);
|
||||
core.timeout.sleepTimeout = null;
|
||||
core.doAction();
|
||||
|
||||
@ -169,25 +169,22 @@ control.prototype._animationFrame_animate = function (timestamp) {
|
||||
if (timestamp - core.animateFrame.animateTime < 50 || !core.status.animateObjs || core.status.animateObjs.length == 0) return;
|
||||
core.clearMap('animate');
|
||||
// 更新帧
|
||||
var animateObjs = [];
|
||||
for (var i=0;i<core.status.animateObjs.length;i++) {
|
||||
for (var i = 0; i < core.status.animateObjs.length; i++) {
|
||||
var obj = core.status.animateObjs[i];
|
||||
if (obj.index == obj.animate.frames.length) {
|
||||
// 绘制完毕
|
||||
delete core.animateFrame.asyncId[obj.id];
|
||||
// 异步执行回调...
|
||||
(function(callback) {
|
||||
setTimeout(function() {
|
||||
(function (callback) {
|
||||
setTimeout(function () {
|
||||
if (callback) callback();
|
||||
});
|
||||
})(obj.callback);
|
||||
}
|
||||
else {
|
||||
}
|
||||
core.status.animateObjs = core.status.animateObjs.filter(function (obj) {
|
||||
return obj.index < obj.animate.frames.length;
|
||||
});
|
||||
core.status.animateObjs.forEach(function (obj) {
|
||||
core.maps._drawAnimateFrame(obj.animate, obj.centerX, obj.centerY, obj.index++);
|
||||
animateObjs.push(obj);
|
||||
}
|
||||
}
|
||||
core.status.animateObjs = animateObjs;
|
||||
});
|
||||
core.animateFrame.animateTime = timestamp;
|
||||
}
|
||||
|
||||
@ -2187,7 +2184,7 @@ control.prototype.playSound = function (sound) {
|
||||
var source = core.musicStatus.audioContext.createBufferSource();
|
||||
source.buffer = core.material.sounds[sound];
|
||||
source.connect(core.musicStatus.gainNode);
|
||||
var id = parseInt(Math.random()*10000000);
|
||||
var id = setTimeout(null);
|
||||
source.onended = function () {
|
||||
delete core.musicStatus.playingSounds[id];
|
||||
}
|
||||
|
||||
@ -1496,7 +1496,7 @@ events.prototype.__action_wait_getValue = function (value) {
|
||||
|
||||
events.prototype._action_waitAsync = function (data, x, y, prefix) {
|
||||
var test = window.setInterval(function () {
|
||||
if (Object.keys(core.animateFrame.asyncId).length == 0) {
|
||||
if (!core.hasAsync()) {
|
||||
clearInterval(test);
|
||||
core.doAction();
|
||||
}
|
||||
@ -1687,6 +1687,10 @@ events.prototype.openSettings = function (fromUserAction) {
|
||||
|
||||
// ------ 一些事件的具体执行过程 ------ //
|
||||
|
||||
events.prototype.hasAsync = function () {
|
||||
return Object.keys(core.animateFrame.asyncId).length > 0 || (core.status.animateObjs || []).length > 0;
|
||||
}
|
||||
|
||||
////// 跟随 //////
|
||||
events.prototype.follow = function (name) {
|
||||
core.status.hero.followers = core.status.hero.followers || [];
|
||||
|
||||
16
libs/maps.js
16
libs/maps.js
@ -1832,18 +1832,17 @@ maps.prototype.drawAnimate = function (name, x, y, callback) {
|
||||
// 播放音效
|
||||
core.playSound(animate.se);
|
||||
|
||||
var animateId = parseInt(Math.random() * 100000000);
|
||||
var id = setTimeout(null);
|
||||
core.status.animateObjs.push({
|
||||
"id": id,
|
||||
"animate": animate,
|
||||
"centerX": centerX,
|
||||
"centerY": centerY,
|
||||
"index": 0,
|
||||
"id": animateId,
|
||||
"callback": callback
|
||||
});
|
||||
|
||||
core.animateFrame.asyncId[animateId] = true;
|
||||
return animateId;
|
||||
return id;
|
||||
}
|
||||
|
||||
////// 绘制动画的某一帧 //////
|
||||
@ -1881,7 +1880,6 @@ maps.prototype.stopAnimate = function (id, doCallback) {
|
||||
for (var i = 0; i < core.status.animateObjs.length; i++) {
|
||||
var obj = core.status.animateObjs[i];
|
||||
if (obj.id == id) {
|
||||
delete core.animateFrame.asyncId[obj.id];
|
||||
if (doCallback) {
|
||||
(function (callback) {
|
||||
setTimeout(function () {
|
||||
@ -1890,10 +1888,8 @@ maps.prototype.stopAnimate = function (id, doCallback) {
|
||||
})(obj.callback);
|
||||
}
|
||||
}
|
||||
core.status.animateObjs.splice(i, 1);
|
||||
if (core.status.animateObjs.length == 0) {
|
||||
}
|
||||
core.status.animateObjs = core.status.animateObjs.filter(function (x) { return x.id != id });
|
||||
if (core.status.animateObjs.length == 0)
|
||||
core.clearMap('animate');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user