Skip to content

Commit aaf82f9

Browse files
committed
Sprite.loadTexture has a new optional stopAnimation boolean parameter which will halt the currently running animation (if any) after changing the texture (based on phaserjs#1029).
1 parent d72e199 commit aaf82f9

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Version 2.0.7 - "Amadicia" - -in development-
6363
### New Features
6464

6565
* ArrayList.setAll - sets the property to the given value on all members of the list.
66+
* Sprite.loadTexture has a new optional `stopAnimation` boolean parameter which will halt the currently running animation (if any) after changing the texture (based on #1029).
6667

6768
### Bug Fixes
6869

build/phaser.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4452,7 +4452,7 @@ declare module Phaser {
44524452
destroy(destroyChildren?: boolean): void;
44534453
drawPolygon(): void;
44544454
kill(): Phaser.Sprite;
4455-
loadTexture(key: any, frame: any): void;
4455+
loadTexture(key: any, frame: any, stopAnimation?: boolean): void;
44564456
overlap(displayObject: any): boolean;
44574457
play(name: string, frameRate?: number, loop?: boolean, killOnComplete?: boolean): Phaser.Animation;
44584458
postUpdate(): void;

src/gameobjects/Sprite.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ Phaser.Sprite.prototype.postUpdate = function() {
355355
* @memberof Phaser.Sprite
356356
* @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Sprite during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture, BitmapData or PIXI.Texture.
357357
* @param {string|number} [frame] - If this Sprite is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index.
358+
* @param {boolean} [stopAnimation=true] - If an animation is already playing on this Sprite you can choose to stop it or let it carry on playing.
358359
*/
359-
Phaser.Sprite.prototype.loadTexture = function (key, frame) {
360+
Phaser.Sprite.prototype.loadTexture = function (key, frame, stopAnimation) {
360361

361362
frame = frame || 0;
362363

@@ -406,6 +407,11 @@ Phaser.Sprite.prototype.loadTexture = function (key, frame) {
406407
this._frame = Phaser.Rectangle.clone(this.texture.frame);
407408
}
408409

410+
if (stopAnimation || typeof stopAnimation === 'undefined')
411+
{
412+
this.animations.stop();
413+
}
414+
409415
};
410416

411417
/**

0 commit comments

Comments
 (0)