From 1bfdcfe92228afc8b531537a726b8623cf707066 Mon Sep 17 00:00:00 2001 From: Robert Kowalski Date: Wed, 24 Jan 2024 19:54:46 -0500 Subject: [PATCH] TileSprite textures are now stored in the TextureManager --- changelog/3.80/CHANGELOG-v3.80.md | 2 +- src/gameobjects/tilesprite/TileSprite.js | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/changelog/3.80/CHANGELOG-v3.80.md b/changelog/3.80/CHANGELOG-v3.80.md index 06799a08a..0aa698056 100644 --- a/changelog/3.80/CHANGELOG-v3.80.md +++ b/changelog/3.80/CHANGELOG-v3.80.md @@ -9,7 +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. +* The `Text` and `TileSprite` Game Objects now place their textures into the global `TextureManager` and a `_textureKey` private string property has been added which contains a UUID to reference that texture. # Bug Fixes diff --git a/src/gameobjects/tilesprite/TileSprite.js b/src/gameobjects/tilesprite/TileSprite.js index 4e32ae45e..faaae6f62 100644 --- a/src/gameobjects/tilesprite/TileSprite.js +++ b/src/gameobjects/tilesprite/TileSprite.js @@ -11,6 +11,7 @@ var GameObject = require('../GameObject'); var GetPowerOfTwo = require('../../math/pow2/GetPowerOfTwo'); var Smoothing = require('../../display/canvas/Smoothing'); var TileSpriteRender = require('./TileSpriteRender'); +var UUID = require('../../utils/string/UUID'); var Vector2 = require('../../math/Vector2'); // bitmask flag for GameObject.renderMask @@ -219,6 +220,16 @@ var TileSprite = new Class({ */ this._crop = this.resetCropObject(); + /** + * The internal unique key to refer to the texture in the TextureManager. + * + * @name Phaser.GameObjects.TileSprite#_textureKey + * @type {string} + * @private + * @since 3.80.0 + */ + this._textureKey = UUID(); + /** * The Texture this Game Object is using to render with. * @@ -226,7 +237,7 @@ var TileSprite = new Class({ * @type {Phaser.Textures.Texture|Phaser.Textures.CanvasTexture} * @since 3.0.0 */ - this.texture = scene.sys.textures.addCanvas(null, this.canvas, true); + this.texture = scene.sys.textures.addCanvas(this._textureKey, this.canvas); /** * The Texture Frame this Game Object is using to render with. @@ -556,7 +567,12 @@ var TileSprite = new Class({ this.displayTexture = null; this.displayFrame = null; - this.texture.destroy(); + var texture = this.texture; + + if (texture) + { + texture.destroy(); + } this.renderer = null; },