Skip to content

Bevy plugin to manage 2d texture in different view angles

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

dothanhtrung/bevy-2dviewangle

bevy_2dviewangle

crates.io docs.rs dependency status pipeline status

Bevy plugin to easier to manage and switch texture base on view angles.

Quickstart

// Struct to store sprite sheet
#[derive(ActorsTexturesCollection, Default)]
struct MyAssets {
    #[textureview(actor = "player", action = "idle", angle = "front")]
    pub idle_front: Handle<Image>,

    // If not specify actor/action, the previous value will be used
    #[textureview(angle = "back")]
    pub idle_back: Handle<Image>,

    // If the angle "right" is not defined, it will be flipped base on the "left" image
    #[textureview(angle = "left")]
    pub idle_left: Handle<Image>,
    
    // If angle is any, other angle which has not been defined will use this value
    #[textureview(angle = "any")]
    pub idle_any_layout: Handle<TextureAtlasLayout>,
}
// Change the sprite sheet by sending event
fn switch_sprite(
    mut actors: Query<(&mut DynamicActor, Entity)>,
    mut action_event: EventWriter<ViewChanged>,
) {
    for (mut act, e) in actors.iter_mut() {
        act.action = ActionMyAssets::Idle;
        act.angle = AngleMyAssets::Right;
        action_event.send(ViewChanged { entity: e });
    }
}

Please see in examples for more detail.

This plugin can work with bevy_asset_loader too:

#[derive(AssetCollection, ActorsTexturesCollection, Resource)]
pub struct MyAssets {
    #[asset(path = "frog_idle_front.png")]
    #[textureview(actor = "frog", action = "idle", angle = "front")]
    pub idle_front: Handle<Image>,

    #[asset(path = "frog_idle_back.png")]
    #[textureview(angle = "back")]
    pub idle_back: Handle<Image>,

    #[asset(path = "frog_idle_left.png")]
    #[textureview(angle = "left")]
    pub idle_left: Handle<Image>,

    #[asset(texture_atlas_layout(tile_size_x = 16., tile_size_y = 16., columns = 1, rows = 3))]
    #[textureview(angle = "any")]
    pub any_layout: Handle<TextureAtlasLayout>,
}

License

Please see LICENSE.

Compatible Bevy Versions

bevy bevy_2dviewangle
0.13 0.2-0.6, branch master
0.12 0.1

About

Bevy plugin to manage 2d texture in different view angles

Topics

Resources

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages