You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In SpriteSheets created from a texture atlas with TextureManager.addSpriteSheetFromAtlas(), the first frame becomes identical to the second frame. In all usage, including animations, the first frame will appear as the second frame instead.
Example Test Code
The following code is pulled directly from the following Phaser 3 Example. I have modified all the animation configurations to only use the first 2 frames in order to demonstrate that the animations derived from the trimmed texture atlases will appear to "freeze" because both frames are identical due to this bug, while their untrimmed counterparts will rapidly display the first 2 frames as expected.
I have identified the cause of problem.
For untrimmed texture atlas frames, Parser.SpriteSheet() is used to create the SpriteSheet. This function adds a __BASE texture source entry.
However, for trimmed texture atlases texture atlases, Parser.SpriteSheetFromAtlas() is used, and this function does not add a __BASE texture source entry. This impacts how the texture is handled in Texture.get().
If a number 0 is passed to this function, this normally would not be a problem for a SpriteSheet because its firstFrame is frame 0 anyway, and everything continues on as expected. However, in the case of a SpriteSheet without a __BASE texture source entry, the firstFrame ends up being the second frame instead due to the following code in Texture.add():
// Set the first frame of the Texture (other than __BASE)// This is used to ensure we don't spam the display with entire// atlases of sprite sheets, but instead just the first frame of them// should the dev incorrectly specify the frame indexif(this.frameTotal===1){this.firstFrame=name;}
Therefore the returned firstFrame is in fact the second frame.
I'm going to open a PR with a minimalist fix. The fix for this particular bug should be as simple as modifying the above check to handle the case where a __BASE texture does not exist.
That being said, it may be worth also having a look at why a __BASE texture entry isn't added in Parser.SpriteSheetFromAtlas() in the first place.
Thanks for opening this issue, and for submitting a PR to fix it. We have merged your PR into the master branch and attributed the work to you in the Change Log. If you need to tweak the code for whatever reason please submit a new PR.
Version
Description
In SpriteSheets created from a texture atlas with
TextureManager.addSpriteSheetFromAtlas()
, the first frame becomes identical to the second frame. In all usage, including animations, the first frame will appear as the second frame instead.Example Test Code
The following code is pulled directly from the following Phaser 3 Example. I have modified all the animation configurations to only use the first 2 frames in order to demonstrate that the animations derived from the trimmed texture atlases will appear to "freeze" because both frames are identical due to this bug, while their untrimmed counterparts will rapidly display the first 2 frames as expected.
Additional Information
I have identified the cause of problem.
For untrimmed texture atlas frames,
Parser.SpriteSheet()
is used to create the SpriteSheet. This function adds a __BASE texture source entry.However, for trimmed texture atlases texture atlases,
Parser.SpriteSheetFromAtlas()
is used, and this function does not add a __BASE texture source entry. This impacts how the texture is handled inTexture.get()
.In
Texture.get()
, there is a check:If a number 0 is passed to this function, this normally would not be a problem for a SpriteSheet because its
firstFrame
is frame 0 anyway, and everything continues on as expected. However, in the case of a SpriteSheet without a __BASE texture source entry, thefirstFrame
ends up being the second frame instead due to the following code inTexture.add()
:Therefore the returned
firstFrame
is in fact the second frame.I'm going to open a PR with a minimalist fix. The fix for this particular bug should be as simple as modifying the above check to handle the case where a __BASE texture does not exist.
That being said, it may be worth also having a look at why a __BASE texture entry isn't added in
Parser.SpriteSheetFromAtlas()
in the first place.Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: