diff --git a/changelog/3.80/CHANGELOG-v3.80.md b/changelog/3.80/CHANGELOG-v3.80.md index baeeebd23..06799a08a 100644 --- a/changelog/3.80/CHANGELOG-v3.80.md +++ b/changelog/3.80/CHANGELOG-v3.80.md @@ -9,6 +9,7 @@ * The `TweenChainBuilder` was incorrectly setting the `persist` flag on the Chain to `true`, which goes against what the documentation says. It now correctly sets it to `false`. This means if you previously had a Tween Chain that was persisting, it will no longer do so, so add the property to regain the feature. * The `dropped` argument has now been adeded to the documentation for the `DRAG_END` and `GAMEOBJECT_DRAG_END` events (thanks @samme) * `Container.onChildDestroyed` is a new internal method used to destroy Container children. Previously, if you destroyed a Game Object in an exclusive Container, the game object would (momentarily) move onto the Scene display list and emit an ADDED_TO_SCENE event. Also, if you added a Sprite to a non-exclusive Container and stopped the Scene, you would get a TypeError (evaluating 'this.anims.destroy'). This happened because the fromChild argument in the DESTROY event was misinterpreted as destroyChild in the Container's remove(), and the Container was calling the Sprite's destroy() again. (thanks @samme) +* The `Text` Game Object now places its texture into the global `TextureManager` and a `_textureKey` private string property has been added to reference that texture. # Bug Fixes diff --git a/src/gameobjects/text/Text.js b/src/gameobjects/text/Text.js index 7fde6f821..69525cb4b 100644 --- a/src/gameobjects/text/Text.js +++ b/src/gameobjects/text/Text.js @@ -14,6 +14,7 @@ var GetValue = require('../../utils/object/GetValue'); var RemoveFromDOM = require('../../dom/RemoveFromDOM'); var TextRender = require('./TextRender'); var TextStyle = require('./TextStyle'); +var UUID = require('../../utils/string/UUID'); /** * @classdesc @@ -261,8 +262,18 @@ var Text = new Class({ */ this._crop = this.resetCropObject(); + /** + * The internal unique key to refer to the texture in the TextureManager. + * + * @name Phaser.GameObjects.Text#_textureKey + * @type {string} + * @private + * @since 3.80.0 + */ + this._textureKey = UUID(); + // Create a Texture for this Text object - this.texture = scene.sys.textures.addCanvas(null, this.canvas, true); + this.texture = scene.sys.textures.addCanvas(this._textureKey, this.canvas); // Set the context to be the CanvasTexture context this.context = this.texture.context; @@ -1520,7 +1531,12 @@ var Text = new Class({ CanvasPool.remove(this.canvas); - this.texture.destroy(); + var texture = this.texture; + + if (texture) + { + texture.destroy(); + } } /**