Skip to content

Commit d5cd37a

Browse files
committed
Texture.remove is a new method that allows you to remove a Frame from a Texture based on its name. Fix phaserjs#4460
1 parent 6c04d99 commit d5cd37a

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/textures/Texture.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,35 @@ var Texture = new Class({
177177
return frame;
178178
},
179179

180+
/**
181+
* Removes the given Frame from this Texture. The Frame is destroyed immediately.
182+
*
183+
* Any Game Objects using this Frame should stop using it _before_ you remove it,
184+
* as it does not happen automatically.
185+
*
186+
* @method Phaser.Textures.Texture#remove
187+
* @since 3.19.0
188+
*
189+
* @param {string} name - The key of the Frame to remove.
190+
*
191+
* @return {boolean} True if a Frame with the matching key was removed from this Texture.
192+
*/
193+
remove: function (name)
194+
{
195+
if (this.has(name))
196+
{
197+
var frame = this.get(name);
198+
199+
frame.destroy();
200+
201+
delete this.frames[name];
202+
203+
return true;
204+
}
205+
206+
return false;
207+
},
208+
180209
/**
181210
* Checks to see if a Frame matching the given key exists within this Texture.
182211
*

0 commit comments

Comments
 (0)