Skip to content

Commit 006d501

Browse files
committed
Added remove method
1 parent 54a5bb4 commit 006d501

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

src/textures/TextureManager.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,50 @@ var TextureManager = new Class({
147147
}
148148
},
149149

150+
/**
151+
* Removes a Texture from the Texture Manager and destroys it. This will immediately
152+
* clear all references to it from the Texture Manager, and if it has one, destroy its
153+
* WebGLTexture. This will emit a `removetexture` event.
154+
*
155+
* Note: If you have any Game Objects still using this texture they will start throwing
156+
* errors the next time they try to render. Make sure that removing the texture is the final
157+
* step when clearing down to avoid this.
158+
*
159+
* @method Phaser.Textures.TextureManager#remove
160+
* @since 3.6.1
161+
*
162+
* @param {(string|Phaser.Textures.Texture)} key - The key of the Texture to remove, or a reference to it.
163+
*
164+
* @return {Phaser.Textures.TextureManager} The Texture Manager.
165+
*/
166+
remove: function (key)
167+
{
168+
if (typeof key === 'string')
169+
{
170+
if (this.exists(key))
171+
{
172+
key = this.get(key);
173+
}
174+
else
175+
{
176+
console.error('No texture found matching key: ' + key)
177+
return this;
178+
}
179+
}
180+
181+
// By this point key should be a Texture, if not, the following fails anyway
182+
if (this.list.hasOwnProperty(key.key))
183+
{
184+
delete this.list[key.key];
185+
186+
key.destroy();
187+
188+
this.emit('removetexture', key.key);
189+
}
190+
191+
return this;
192+
},
193+
150194
/**
151195
* Adds a new Texture to the Texture Manager created from the given Base64 encoded data.
152196
*

0 commit comments

Comments
 (0)