Skip to content

Commit

Permalink
Texture.add will no longer let you add a frame to a texture with th…
Browse files Browse the repository at this point in the history
…e same name or index as one that already exists in the texture. Doing so will now return `null` instead of a Frame object, and the `frameTotal` will never be incremented. Fix #4459
  • Loading branch information
photonstorm committed Apr 8, 2019
1 parent ce2d986 commit f552dde
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -103,6 +103,7 @@ Notes:
* `Tween.stop` assumed that the parent was the TweenManager. If the Tween has been added to the Timeline, that was not true and the stop method crashed (thanks @TadejZupancic)
* Calling `Tween.restart` multiple times in a row would cause the tween to freeze. It will now disregard all additional calls to `restart` if it's already in a pending state (thanks @rgk)
* Tween Timelines would only apply the `delay` value of a child tween once and not on loop. Fix #3841 (thanks @Edwin222 @Antriel)
* `Texture.add` will no longer let you add a frame to a texture with the same name or index as one that already exists in the texture. Doing so will now return `null` instead of a Frame object, and the `frameTotal` will never be incremented. Fix #4459 (thanks @BigZaphod)

### Examples, Documentation and TypeScript

Expand Down
9 changes: 8 additions & 1 deletion src/textures/Texture.js
Expand Up @@ -137,6 +137,8 @@ var Texture = new Class({
* Adds a new Frame to this Texture.
*
* A Frame is a rectangular region of a TextureSource with a unique index or string-based key.
*
* The name given must be unique within this Texture. If it already exists, this method will return `null`.
*
* @method Phaser.Textures.Texture#add
* @since 3.0.0
Expand All @@ -148,10 +150,15 @@ var Texture = new Class({
* @param {number} width - The width of this Frame.
* @param {number} height - The height of this Frame.
*
* @return {Phaser.Textures.Frame} The Frame that was added to this Texture.
* @return {?Phaser.Textures.Frame} The Frame that was added to this Texture, or `null` if the given name already exists.
*/
add: function (name, sourceIndex, x, y, width, height)
{
if (this.has(name))
{
return null;
}

var frame = new Frame(this, name, sourceIndex, x, y, width, height);

this.frames[name] = frame;
Expand Down

0 comments on commit f552dde

Please sign in to comment.