From ba08f55361c4cae4b5e6205561f7c3660bb1a650 Mon Sep 17 00:00:00 2001 From: ckcz123 Date: Tue, 18 Sep 2018 18:51:24 +0800 Subject: [PATCH] Async Animate --- _server/blockly/MotaAction.g4 | 8 ++++---- docs/event.md | 7 +++++-- libs/events.js | 10 ++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/_server/blockly/MotaAction.g4 b/_server/blockly/MotaAction.g4 index 5f4dac99..b4e4f01d 100644 --- a/_server/blockly/MotaAction.g4 +++ b/_server/blockly/MotaAction.g4 @@ -816,13 +816,13 @@ return code; */; animate_s - : '显示动画' IdString '位置' EvalString? Newline + : '显示动画' IdString '位置' EvalString? '不等待绘制完毕' Bool Newline /* animate_s tooltip : animate:显示动画,位置填hero或者1,2形式的位置,或者不填代表当前事件点 helpUrl : https://ckcz123.github.io/mota-js/#/event?id=animate%EF%BC%9A%E6%98%BE%E7%A4%BA%E5%8A%A8%E7%94%BB -default : ["zone","hero"] +default : ["zone","hero",false] colour : this.soundColor if (EvalString_0) { if(/^flag:[0-9a-zA-Z_][0-9a-zA-Z_\-]*,flag:[0-9a-zA-Z_][0-9a-zA-Z_\-]*$/.test(EvalString_0)) { @@ -835,7 +835,7 @@ if (EvalString_0) { throw new Error('此处只能填hero或者1,2形式的位置,或者不填代表当前事件点'); } } -var code = '{"type": "animate", "name": "'+IdString_0+'"'+EvalString_0+'},\n'; +var code = '{"type": "animate", "name": "'+IdString_0+'"'+EvalString_0+', "async": '+Bool_0+'},\n'; return code; */; @@ -1803,7 +1803,7 @@ ActionParser.prototype.parseAction = function() { var animate_loc = data.loc||''; if(animate_loc && animate_loc!=='hero')animate_loc = animate_loc[0]+','+animate_loc[1]; this.next = MotaActionBlocks['animate_s'].xmlText([ - data.name,animate_loc,this.next]); + data.name,animate_loc,data.async||0,this.next]); break; case "viberate": // 画面震动 this.next = MotaActionBlocks['viberate_s'].xmlText([data.time||0, this.next]); diff --git a/docs/event.md b/docs/event.md index bc1a9561..bad92300 100644 --- a/docs/event.md +++ b/docs/event.md @@ -753,7 +753,8 @@ name为可选的,是要取消跟随的行走图文件名。 "x,y": [ // 实际执行的事件列表 {"type": "animate", "name": "yongchang", "loc": [1,3]}, // 在(1,3)显示“咏唱魔法”动画 {"type": "animate", "name": "zone", "loc": "hero"}, // 在勇士位置显示“领域”动画 - {"type": "animate", "name": "hand"} // 可以不指定loc,则默认为当前事件点 + {"type": "animate", "name": "hand"}, // 可以不指定loc,则默认为当前事件点 + {"type": "animate", "async": true}, // 异步,不等待动画绘制完毕 ] ``` @@ -763,7 +764,9 @@ loc为动画的位置,可以是`[x,y]`表示在(x,y)点显示,也可以是 loc可忽略,如果忽略则显示为事件当前点。 -在动画播放结束后才会继续执行下一个事件。 +如果async指定为true,则不会等待动画绘制完毕,立刻执行下个事件。 + +否则,在动画播放结束后才会继续执行下一个事件。 ### showImage:显示图片 diff --git a/libs/events.js b/libs/events.js index e55bcee9..c39f31e7 100644 --- a/libs/events.js +++ b/libs/events.js @@ -508,9 +508,15 @@ events.prototype.doAction = function() { y=core.calValue(data.loc[1]); } } - core.drawAnimate(data.name, x, y, function () { + if (data.async) { + core.drawAnimate(data.name, x, y); core.events.doAction(); - }) + } + else { + core.drawAnimate(data.name, x, y, function () { + core.events.doAction(); + }) + } break; case "move": // 移动事件 if (core.isset(data.loc)) {