Skip to content

How can exchange the texture of a SpriteBundle at runtime? #8054

Answered by NiklasEi
fabiandiez asked this question in Q&A
Discussion options

You must be logged in to vote

The answer of #2892 also applies here. You can change the value of the Handle<Image> component.
Slightly adjusted code example from #2892:

fn update_sprite(asset_server: Res<AssetServer>, query: Query<&mut Handle<Image>, With<MyMarkerComponent>>) {
    let mut handle = query.single_mut();
    *handle = asset_server.load("sprites/new_sprite.png");
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fabiandiez
Comment options

Answer selected by fabiandiez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants