diff --git a/src/extras/MovieClip.js b/src/extras/MovieClip.js index fe079b8..6d94445 100644 --- a/src/extras/MovieClip.js +++ b/src/extras/MovieClip.js @@ -72,6 +72,14 @@ this.onComplete = null; /** + * Function to call when a MovieClip changes which texture is being rendered + * + * @method + * @memberof PIXI.extras.MovieClip# + */ + this.onFrameChange = null; + + /** * Elapsed time since animation has been started, used internally to display current texture * * @member {number} @@ -127,10 +135,19 @@ { this.stop(); + const previousFrame = this.currentFrame; this._currentTime = frameNumber; - this._texture = this._textures[this.currentFrame]; - this._textureID = -1; + if (previousFrame !== this.currentFrame) + { + this._texture = this._textures[this.currentFrame]; + this._textureID = -1; + + if (this.onFrameChange) + { + this.onFrameChange(this.currentFrame); + } + } } /** @@ -152,6 +169,7 @@ update(deltaTime) { const elapsed = this.animationSpeed * deltaTime; + const previousFrame = this.currentFrame; if (this._durations !== null) { @@ -201,8 +219,16 @@ } else { - this._texture = this._textures[this.currentFrame]; - this._textureID = -1; + if (previousFrame !== this.currentFrame) + { + this._texture = this._textures[this.currentFrame]; + this._textureID = -1; + + if (this.onFrameChange) + { + this.onFrameChange(this.currentFrame); + } + } } }