2

I'm using TextureAtlasBuilder to produce a TextureAtlas. I'm adding multiple textures to the atlas using the add_texture method. I'm then using that texture atlas as part of a sprite entity created from a SpriteSheetComponents bundle.

When changing the sprite's index, the resulting texture is not what I'm expecting. I'm assuming that the textures in the texture atlas reflect the order in which they were added while building it. Is that an incorrect assumption?

w.brian
  • 16,296
  • 14
  • 69
  • 118

1 Answers1

3

The order in which you call add_texture does not guarantee the order in which they are stored in the textures Vec. This is because the current implementation (as of bevy 0.3.1) uses a HashMap to store the placements of the rectangles, thus not preserving the order of insertion.

Since the project is in its infancy, you might consider creating an issue in the project to have this changed.

For the time being, you could either try combining the sprites outside of Bevy and then reading in the TextureAtlas directly from that asset like in the sprite sheet example.

EtTuBrute
  • 502
  • 5
  • 16