Group.removeAll has a new argument destroyTexture which allows you to optionally destroy the BaseTexture of each child, as it is removed from the Group (thanks @stoneman1 #2487)

This commit is contained in:
photonstorm 2016-06-03 13:10:14 +01:00
parent ae5be7ac92
commit 9ae43757b9
3 changed files with 12 additions and 4 deletions

View file

@ -358,6 +358,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* TilemapLayer.postUpdate could potentially be called several times per frame (depending on device frame rate), which would cause multiple texture redraws, even though only the last texture is used during rendering. This has now been modified so that the local TilemapLayer canvas is only re-rendered once per frame, during the rendering phase, and not during the logic update phase. * TilemapLayer.postUpdate could potentially be called several times per frame (depending on device frame rate), which would cause multiple texture redraws, even though only the last texture is used during rendering. This has now been modified so that the local TilemapLayer canvas is only re-rendered once per frame, during the rendering phase, and not during the logic update phase.
* Stage has had all of its core update loops modified, so they now iterate through the display list forwards, instead of in reverse. Stage.postUpdate is now also a lot smaller, with no conditional branching if there is a Camera Target or not. * Stage has had all of its core update loops modified, so they now iterate through the display list forwards, instead of in reverse. Stage.postUpdate is now also a lot smaller, with no conditional branching if there is a Camera Target or not.
* Within RequestAnimationFrame both `updateRAF` and `updateSetTimeout` now only call `game.update` if `isRunning` is true. This should avoid asynchronous Game destroy errors under environments like Angular (thanks @flogvit #2521) * Within RequestAnimationFrame both `updateRAF` and `updateSetTimeout` now only call `game.update` if `isRunning` is true. This should avoid asynchronous Game destroy errors under environments like Angular (thanks @flogvit #2521)
* Group.removeAll has a new argument `destroyTexture` which allows you to optionally destroy the BaseTexture of each child, as it is removed from the Group (thanks @stoneman1 #2487)
### Bug Fixes ### Bug Fixes

View file

@ -2173,16 +2173,23 @@ Phaser.Group.prototype.moveAll = function (group, silent) {
}; };
/** /**
* Removes all children from this group, but does not remove the group from its parent. * Removes all children from this Group, but does not remove the group from its parent.
*
* The children can be optionally destroyed as they are removed.
*
* You can also optionally also destroy the BaseTexture the Child is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
* *
* @method Phaser.Group#removeAll * @method Phaser.Group#removeAll
* @param {boolean} [destroy=false] - If true `destroy` will be invoked on each removed child. * @param {boolean} [destroy=false] - If true `destroy` will be invoked on each removed child.
* @param {boolean} [silent=false] - If true the children will not dispatch their `onRemovedFromGroup` events. * @param {boolean} [silent=false] - If true the children will not dispatch their `onRemovedFromGroup` events.
* @param {boolean} [destroyTexture=false] - If true, and if the `destroy` argument is also true, the BaseTexture belonging to the Child is also destroyed. Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
*/ */
Phaser.Group.prototype.removeAll = function (destroy, silent) { Phaser.Group.prototype.removeAll = function (destroy, silent, destroyTexture) {
if (destroy === undefined) { destroy = false; } if (destroy === undefined) { destroy = false; }
if (silent === undefined) { silent = false; } if (silent === undefined) { silent = false; }
if (destroyTexture === undefined) { destroyTexture = false; }
if (this.children.length === 0) if (this.children.length === 0)
{ {
@ -2202,7 +2209,7 @@ Phaser.Group.prototype.removeAll = function (destroy, silent) {
if (destroy && removed) if (destroy && removed)
{ {
removed.destroy(true); removed.destroy(true, destroyTexture);
} }
} }
while (this.children.length > 0); while (this.children.length > 0);

View file

@ -1728,7 +1728,7 @@ declare module "phaser" {
preUpdate(): void; preUpdate(): void;
previous(): void; previous(): void;
remove(child: any, destroy?: boolean, silent?: boolean): boolean; remove(child: any, destroy?: boolean, silent?: boolean): boolean;
removeAll(destroy?: boolean, silent?: boolean): void; removeAll(destroy?: boolean, silent?: boolean, destroyTexture?: boolean): void;
removeBetween(startIndex: number, endIndex?: number, destroy?: boolean, silent?: boolean): void; removeBetween(startIndex: number, endIndex?: number, destroy?: boolean, silent?: boolean): void;
removeFromHash(child: PIXI.DisplayObject): boolean; removeFromHash(child: PIXI.DisplayObject): boolean;
replace(oldChild: any, newChild: any): any; replace(oldChild: any, newChild: any): any;