bevy icon indicating copy to clipboard operation
bevy copied to clipboard

add index_range for TextureAtlas

Open useyourfeelings opened this issue 1 year ago • 2 comments

Objective

To simplify index updating for TextureAtlas when playing animation.

Solution

Add index_range and advance_index() for TextureAtlas.

So

// init
let animation_indices = AnimationIndices { first: 1, last: 6 };

TextureAtlas {
    layout: texture_atlas_layout,
    index: animation_indices.first,
},

// update
atlas.index = if atlas.index == indices.last {
    indices.first
} else {
    atlas.index + 1
};

will become

// init
TextureAtlas {
    layout: texture_atlas_layout,
    index: 1,
    index_range: (1, 6)
},

// update
atlas.advance_index();

Testing

Tested all examples related to TextureAtlas.

useyourfeelings avatar Dec 02 '24 18:12 useyourfeelings

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

github-actions[bot] avatar Dec 02 '24 18:12 github-actions[bot]

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy? It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

github-actions[bot] avatar Dec 03 '24 16:12 github-actions[bot]

Sort of opposed to this change. I feel like it's of way too limited utility to be given prime real estate in the TextureAtlas struct, and I'm not sure that animation metadata belongs in there anyway.

Definitely want to add stuff to help with 2d animations... I just think that whatever we end up with will look nothing like what is being done in that PR.

I'd maybe implement it as an optional AtlasAnimation { frames: Vec<usize>, index: usize } or AtlasAnimation { start: usize, end: usize, index: usize} component with helper methods or something. But that last one feels pretty restrictive, and they're both missing timing information. But it might be a better starting point.

rparrett avatar Dec 05 '24 18:12 rparrett