Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add texture atlas sprites #22

Merged
merged 14 commits into from
Dec 31, 2022

Conversation

cBournhonesque
Copy link
Contributor

PR to be able to handle sprites that come from texture atlas.

My use-case is that all my image assets are stored in a texture atlas, so I need this change to be able to use the library.
I think that it would be interesting to let users have a particle sprite-sheet and the particles randomly use a sprite from the sprite sheet.

This PR is unpolished, I just opened it to see if it's a good idea for you.
If so, I would probably add an SpriteEnum to have 2 mutually exclusive options (Sprite or TextureAtlasSprite)

@abnormalbrain
Copy link
Owner

@cBournhonesque Thanks for the PR! I think this is an excellent idea and I agree with your approach.

I think something like a ParticleTexture enum with Sprite and TextureAtlas variants that contain the appropriate Handles would be good, in place of default_sprite.

I also like the idea of optionally randomizing the chosen Sprite on spawn. I'm not sure JitteredValue would be quite the right option for that, though. Particularly since it currently only operates on floats, and we'd need a usize. Also all valid options for the particle system system would have to exist in sequential indices in the texture atlas.

We can leave this part off for now and add it later too, but I think the best approach would be to do allow either defining something like RandomRange(Range<T>) or RandomChoice(Vec<T>) which allow ranges or sets of arbitrary numbers. What do you think?

@abnormalbrain abnormalbrain added the enhancement New feature or request label Dec 31, 2022
@cBournhonesque
Copy link
Contributor Author

Sounds great! I'll work on both changes!
Another thing that could be useful is z-axis rotation of the particles. I don't think i saw it in the options.

@abnormalbrain
Copy link
Owner

Yeah, there's no rotation currently, but that would also be great to add. For the sake of scope, that should probably be a different PR. I'll file an issue with some details.

@cBournhonesque
Copy link
Contributor Author

cBournhonesque commented Dec 31, 2022

@abnormalbrain I adjusted my PR to match your comment :)

I didn't add an example but have been using it in my game with TextureAtlasSprite

Probably another variant of RandomChoice would be an InOrderPicker where the values just cycle through the possible choices (Vec) in-order.

@abnormalbrain
Copy link
Owner

@cBournhonesque This looks great! Left one comment for discussion about copy vs clone, but I'm very happy with this and willing to merge as is.

@abnormalbrain abnormalbrain merged commit 4bff905 into abnormalbrain:main Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants