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
A common problem when dealing with physics is that the simulation often uses meters instead of pixels as a unit of measurement. That means you should use an appropriate Viewport with world units and scale your sprites down by a Pixels Per Meter ratio. In Sprite, this would be sprite.setScale(1 / PPM).
That usually works, however the issue is that this does not work for sprites created from a TextureAtlas and the atlas was set to stripwhitespace. AtlasSprite handles most of the adjustments necessary for other transformations, but Sprite#getVertices() is not overridden. This method handles the localized position of the Sprite after scaling. So when the user scales down the sprite, the Sprite is drawn in the incorrect position.
Upon further investigation, I found that there is a similar problem with ParticleEffect. It turns out that ParticleEffect does not implement AtlasSprite at all, causing even more issues. This one is a little more complicated because Particle extends Sprite directly and is tightly paired with the functionality of ParticleEmitter. Note that the problems with ParticleEffect persist even if you just set the scale in the particle effect file.
In the end, you could just say that you shouldn't use the stripwhitespace option (and potentially rotate too). However, that is not documented and seems like an important oversight.
Reproduction steps/code
Create a texture atlas with the stripwhitespacex and stripwhitespacey options activated. Make sure to also use images with a lot of whitespace to make a noticeable difference. You may use code like this to reproduce:
Issue details
A common problem when dealing with physics is that the simulation often uses meters instead of pixels as a unit of measurement. That means you should use an appropriate Viewport with world units and scale your sprites down by a Pixels Per Meter ratio. In Sprite, this would be sprite.setScale(1 / PPM).
That usually works, however the issue is that this does not work for sprites created from a TextureAtlas and the atlas was set to stripwhitespace. AtlasSprite handles most of the adjustments necessary for other transformations, but Sprite#getVertices() is not overridden. This method handles the localized position of the Sprite after scaling. So when the user scales down the sprite, the Sprite is drawn in the incorrect position.
Upon further investigation, I found that there is a similar problem with ParticleEffect. It turns out that ParticleEffect does not implement AtlasSprite at all, causing even more issues. This one is a little more complicated because Particle extends Sprite directly and is tightly paired with the functionality of ParticleEmitter. Note that the problems with ParticleEffect persist even if you just set the scale in the particle effect file.
In the end, you could just say that you shouldn't use the stripwhitespace option (and potentially rotate too). However, that is not documented and seems like an important oversight.
Reproduction steps/code
Create a texture atlas with the stripwhitespacex and stripwhitespacey options activated. Make sure to also use images with a lot of whitespace to make a noticeable difference. You may use code like this to reproduce:
You may also use my atlas from my latest jam game as reference:
textures.zip
particles.zip
This version does not use stripwhitespace and works as intended:
textures2.zip
Incorrect positioning with stripwhitespace:
Correct positioning without stripwhitespace:
Version of libGDX and/or relevant dependencies
1.12.1
Please select the affected platforms
The text was updated successfully, but these errors were encountered: