diff --git a/src/ticker/Ticker.js b/src/ticker/Ticker.js index 151a894..3cb0ff9 100644 --- a/src/ticker/Ticker.js +++ b/src/ticker/Ticker.js @@ -9,12 +9,14 @@ * does a bit too much for what this is for. * This is simple enough to keep track of and contribute * back to the eventemitter3 project in the near future. + * Note: No need to check for specific event because the + * composed emitter only uses a single event. * * @private */ function hasListeners(emitter) { - return !!(emitter._events && emitter._events[TICK]); + return !!emitter._events; } /** @@ -46,14 +48,13 @@ if (_this.started) { + // Invoke listeners now _this.update(time); - } - // Check here because listeners could have side effects - // and may have modified state during frame execution. - // A new frame may have been requested or listeners removed. - if (_this.started && _this._requestId === null && hasListeners(_this._emitter)) - { - _this._requestId = requestAnimationFrame(_this._tick); + // Listener side effects may have modified ticker state. + if (_this.started && _this._requestId === null && hasListeners(_this._emitter)) + { + _this._requestId = requestAnimationFrame(_this._tick); + } } }; /** diff --git a/src/ticker/Ticker.js b/src/ticker/Ticker.js index 151a894..3cb0ff9 100644 --- a/src/ticker/Ticker.js +++ b/src/ticker/Ticker.js @@ -9,12 +9,14 @@ * does a bit too much for what this is for. * This is simple enough to keep track of and contribute * back to the eventemitter3 project in the near future. + * Note: No need to check for specific event because the + * composed emitter only uses a single event. * * @private */ function hasListeners(emitter) { - return !!(emitter._events && emitter._events[TICK]); + return !!emitter._events; } /** @@ -46,14 +48,13 @@ if (_this.started) { + // Invoke listeners now _this.update(time); - } - // Check here because listeners could have side effects - // and may have modified state during frame execution. - // A new frame may have been requested or listeners removed. - if (_this.started && _this._requestId === null && hasListeners(_this._emitter)) - { - _this._requestId = requestAnimationFrame(_this._tick); + // Listener side effects may have modified ticker state. + if (_this.started && _this._requestId === null && hasListeners(_this._emitter)) + { + _this._requestId = requestAnimationFrame(_this._tick); + } } }; /** diff --git a/src/ticker/index.js b/src/ticker/index.js index 188dab2..6547969 100644 --- a/src/ticker/index.js +++ b/src/ticker/index.js @@ -30,7 +30,7 @@ * var stage = new PIXI.Container(); * var interactionManager = PIXI.interaction.InteractionManager(renderer); * document.body.appendChild(renderer.view); - * ticker.add(function () { + * ticker.add(function (time) { * renderer.render(stage); * }); * @@ -38,12 +38,12 @@ * // Or you can just update it manually. * ticker.autoStart = false; * ticker.stop(); - * function animate() { + * function animate(time) { * ticker.update(time); * renderer.render(stage); * requestAnimationFrame(animate); * } - * animate(); + * animate(performance.now()); * * @type {PIXI.ticker.Ticker} * @memberof PIXI.ticker