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'
|
if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep'
|
||||||
&& !core.status.event.data.current.noSkip) {
|
&& !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);
|
clearTimeout(core.timeout.sleepTimeout);
|
||||||
core.timeout.sleepTimeout = null;
|
core.timeout.sleepTimeout = null;
|
||||||
core.doAction();
|
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'
|
if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep'
|
||||||
&& !core.status.event.data.current.noSkip) {
|
&& !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);
|
clearTimeout(core.timeout.sleepTimeout);
|
||||||
core.timeout.sleepTimeout = null;
|
core.timeout.sleepTimeout = null;
|
||||||
core.doAction();
|
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;
|
if (timestamp - core.animateFrame.animateTime < 50 || !core.status.animateObjs || core.status.animateObjs.length == 0) return;
|
||||||
core.clearMap('animate');
|
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];
|
var obj = core.status.animateObjs[i];
|
||||||
if (obj.index == obj.animate.frames.length) {
|
if (obj.index == obj.animate.frames.length) {
|
||||||
// 绘制完毕
|
(function (callback) {
|
||||||
delete core.animateFrame.asyncId[obj.id];
|
setTimeout(function () {
|
||||||
// 异步执行回调...
|
|
||||||
(function(callback) {
|
|
||||||
setTimeout(function() {
|
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
});
|
});
|
||||||
})(obj.callback);
|
})(obj.callback);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
core.maps._drawAnimateFrame(obj.animate, obj.centerX, obj.centerY, obj.index++);
|
|
||||||
animateObjs.push(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
core.status.animateObjs = animateObjs;
|
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++);
|
||||||
|
});
|
||||||
core.animateFrame.animateTime = timestamp;
|
core.animateFrame.animateTime = timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2187,7 +2184,7 @@ control.prototype.playSound = function (sound) {
|
|||||||
var source = core.musicStatus.audioContext.createBufferSource();
|
var source = core.musicStatus.audioContext.createBufferSource();
|
||||||
source.buffer = core.material.sounds[sound];
|
source.buffer = core.material.sounds[sound];
|
||||||
source.connect(core.musicStatus.gainNode);
|
source.connect(core.musicStatus.gainNode);
|
||||||
var id = parseInt(Math.random()*10000000);
|
var id = setTimeout(null);
|
||||||
source.onended = function () {
|
source.onended = function () {
|
||||||
delete core.musicStatus.playingSounds[id];
|
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) {
|
events.prototype._action_waitAsync = function (data, x, y, prefix) {
|
||||||
var test = window.setInterval(function () {
|
var test = window.setInterval(function () {
|
||||||
if (Object.keys(core.animateFrame.asyncId).length == 0) {
|
if (!core.hasAsync()) {
|
||||||
clearInterval(test);
|
clearInterval(test);
|
||||||
core.doAction();
|
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) {
|
events.prototype.follow = function (name) {
|
||||||
core.status.hero.followers = core.status.hero.followers || [];
|
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);
|
core.playSound(animate.se);
|
||||||
|
|
||||||
var animateId = parseInt(Math.random() * 100000000);
|
var id = setTimeout(null);
|
||||||
core.status.animateObjs.push({
|
core.status.animateObjs.push({
|
||||||
|
"id": id,
|
||||||
"animate": animate,
|
"animate": animate,
|
||||||
"centerX": centerX,
|
"centerX": centerX,
|
||||||
"centerY": centerY,
|
"centerY": centerY,
|
||||||
"index": 0,
|
"index": 0,
|
||||||
"id": animateId,
|
|
||||||
"callback": callback
|
"callback": callback
|
||||||
});
|
});
|
||||||
|
|
||||||
core.animateFrame.asyncId[animateId] = true;
|
return id;
|
||||||
return animateId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 绘制动画的某一帧 //////
|
////// 绘制动画的某一帧 //////
|
||||||
@ -1881,7 +1880,6 @@ maps.prototype.stopAnimate = function (id, doCallback) {
|
|||||||
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];
|
var obj = core.status.animateObjs[i];
|
||||||
if (obj.id == id) {
|
if (obj.id == id) {
|
||||||
delete core.animateFrame.asyncId[obj.id];
|
|
||||||
if (doCallback) {
|
if (doCallback) {
|
||||||
(function (callback) {
|
(function (callback) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
@ -1890,10 +1888,8 @@ maps.prototype.stopAnimate = function (id, doCallback) {
|
|||||||
})(obj.callback);
|
})(obj.callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
core.status.animateObjs.splice(i, 1);
|
|
||||||
if (core.status.animateObjs.length == 0) {
|
|
||||||
core.clearMap('animate');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
core.status.animateObjs = core.status.animateObjs.filter(function (x) { return x.id != id });
|
||||||
|
if (core.status.animateObjs.length == 0)
|
||||||
|
core.clearMap('animate');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user