diff --git a/src/engine/runtime.js b/src/engine/runtime.js index 0f0c74a86f3..024bfe57f37 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -471,6 +471,7 @@ class Runtime extends EventEmitter { this._lastStepTime = Date.now(); this.interpolationEnabled = false; + this.interpolate = interpolate; this._defaultStoredSettings = this._generateAllProjectOptions(); @@ -643,6 +644,20 @@ class Runtime extends EventEmitter { return 'INTERPOLATION_CHANGED'; } + /** + * Event called before interpolation data is set. + */ + static get BEFORE_INTERPOLATE () { + return 'BEFORE_INTERPOLATE'; + } + + /** + * Event called after interpolation data is set. + */ + static get AFTER_INTERPOLATE () { + return 'AFTER_INTERPOLATE'; + } + /** * Event name for stage size changing. * @const {string} diff --git a/src/engine/tw-interpolate.js b/src/engine/tw-interpolate.js index 3556dffd224..e33318a9cc2 100644 --- a/src/engine/tw-interpolate.js +++ b/src/engine/tw-interpolate.js @@ -51,10 +51,18 @@ const interpolate = (runtime, time) => { } // Don't waste time interpolating sprites that are hidden. - if (!target.visible) { + if ( + !target.visible || + ( + target.effects.ghost === 100 && + interpolationData.ghost === 100 + ) + ) { continue; } + runtime.emit(runtime.constructor.BEFORE_INTERPOLATE, target); + const drawableID = target.drawableID; // Position interpolation. @@ -131,6 +139,8 @@ const interpolate = (runtime, time) => { renderer.updateDrawableDirectionScale(drawableID, direction, scale); } } + + runtime.emit(runtime.constructor.AFTER_INTERPOLATE, target); } }; diff --git a/src/virtual-machine.js b/src/virtual-machine.js index e02d87222a2..2d31cbda96c 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -184,6 +184,12 @@ class VirtualMachine extends EventEmitter { this.runtime.on(Runtime.INTERPOLATION_CHANGED, framerate => { this.emit(Runtime.INTERPOLATION_CHANGED, framerate); }); + this.runtime.on(Runtime.BEFORE_INTERPOLATE, target => { + this.emit(Runtime.BEFORE_INTERPOLATE, target); + }); + this.runtime.on(Runtime.AFTER_INTERPOLATE, target => { + this.emit(Runtime.AFTER_INTERPOLATE, target); + }); this.runtime.on(Runtime.STAGE_SIZE_CHANGED, (width, height) => { this.emit(Runtime.STAGE_SIZE_CHANGED, width, height); });