Sprite (and all Game Objects) have a new argument in their destroy method: destroyTexture. This boolean (which is false by default) controls if the BaseTexture of the Game Object should be destroyed or not. This is extremely useful in situations where you've got a lot of dynamic assets you no longer need, such as textures created from BitmapDatas. You must set the destroyTexture argument yourself. This can be done in a custom Game Object destroy method or as part of your state shutdown (#2261)

This commit is contained in:
Richard Davey 2016-02-03 11:41:18 +00:00
parent 8043d29aa6
commit 034428e92c
2 changed files with 16 additions and 1 deletions

View file

@ -273,6 +273,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
* BitmapText.cleanText is a new method that will scan the given text and either remove or replace all characters that are not present in the font data.
* ArcadePhysics.Body.onCeiling is a new complementary method to go with onFloor (thanks @yigitozdemir #1610)
* Text.precalculateWordWrap allows you to run your text through the Text word wrap function, which is handy if you need to handle pagination on longer pieces of text (thanks @slashman #2277)
* Sprite (and all Game Objects) have a new argument in their destroy method: `destroyTexture`. This boolean (which is false by default) controls if the BaseTexture of the Game Object should be destroyed or not. This is extremely useful in situations where you've got a lot of dynamic assets you no longer need, such as textures created from BitmapDatas. You must set the `destroyTexture` argument yourself. This can be done in a custom Game Object destroy method or as part of your state shutdown (#2261)
### Updates
@ -290,6 +291,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
* Added a typescript section to the bower and npm configs to support `tsd link` (thanks @mjohnsonengr #2189 #2180)
* SoundManager.destroy now calls AudioContext.close (thanks @stoneman1 #2237)
* Sound.onEndedHandler now sets Sound.currentTime to be Sound.durationMS (thanks @stoneman1 #2237)
* BitmapData would always create a private `_swapCanvas` which was a clone of its main canvas used for advanced movement operations. This no longer happens. The swap canvas is created only as needed, by those functions that use it (specifically `moveH` and `moveV`), meaning a BitmapData will now use half the amount of memory it used to, and you'll have half the amount of canvas DOM elements created (unless you make heavy use of the move functions).
### Bug Fixes
@ -311,11 +313,13 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
* Specifying Phaser.ScaleManager.EXACT_FIT as the scaleMode in a game config object would fail to use the scale mode (thanks @06wj #2248)
* BitmapText would crash if it tried to render a character that didn't exist in the font set. Any character that doesn't exist in the font set now renders a space character instead.
* BitmapText would load and parse the kerning data from the font, but would never use it when rendering. The kerning values are now applied on rendering as well (thanks @veu #2165)
* SinglePad.callbackContext is now set through addCallbacks method (thanks @puzzud #2161)
### Pixi Updates
Please note that Phaser uses a custom build of Pixi and always has done. The following changes have been made to our custom build, not to Pixi in general.
* BaseTexture.destroy no longer checks for the `_pixiId` property on the canvas before removing it from the CanvasPool, meaning it's now destroying a lot more canvas elements than it was in the past!
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -27,14 +27,19 @@ Phaser.Component.Destroy.prototype = {
*
* If this Game Object has the Events component it will also dispatch the `onDestroy` event.
*
* You can optionally also destroy the BaseTexture this Game Object is using. Be careful if you've
* more than one Game Object sharing the same BaseTexture.
*
* @method
* @param {boolean} [destroyChildren=true] - Should every child of this object have its destroy method called as well?
* @param {boolean} [destroyTexture=false] - Destroy the BaseTexture this Game Object is using? Note that if another Game Object is sharing the same BaseTexture it will invalidate it.
*/
destroy: function (destroyChildren) {
destroy: function (destroyChildren, destroyTexture) {
if (this.game === null || this.destroyPhase) { return; }
if (destroyChildren === undefined) { destroyChildren = true; }
if (destroyTexture === undefined) { destroyTexture = false; }
this.destroyPhase = true;
@ -141,6 +146,12 @@ Phaser.Component.Destroy.prototype = {
this._destroyCachedSprite();
// Texture?
if (destroyTexture)
{
this.texture.destroy(true);
}
this.destroyPhase = false;
this.pendingDestroy = false;