#How to have a SpriteBundle update it's image based on user keyboard or button input

5 messages · Page 1 of 1 (latest)

dusky plaza
#

I'm working on a project that based on the number of keyboard keys or mouse buttons are pressed the game will change what image the entity uses.

I've looked into parent and child relationships and changing the visibility but that gets messy as there's one image per button combination (no buttons pressed, left, right, both pressed). I'm not sure how to get a query that lets me turn off the active one and turn on the needed one.

Is there a cleaner way to have an entity keep all of its transforms but update the underlying image that's rendered?

faint crypt
#

You can query for the sprite's Handle<Image> and set it to a different handle.

dusky plaza
#

So something like this?
mut query: Query<(&mut Handle<Image>, &mut SpriteBundle), With<MouseReact>)

faint crypt
#

Yes on the handle part, but SpriteBundle isn't a component so you can't query for it. (bundles are just a convenient way to spawn a bunch of components.)