#bevy #angle #default #image #sheet #events #value

bevy_2dviewangle

Bevy plugin for easier to switch texture base on view angles

21 unstable releases (10 breaking)

new 0.10.0 Apr 25, 2025
0.9.0 Dec 6, 2024
0.8.1 Oct 7, 2024
0.7.1 Jul 17, 2024
0.2.0 Feb 26, 2024

#449 in Game dev

Download history 3/week @ 2025-02-02 2/week @ 2025-02-09 4/week @ 2025-02-16 2/week @ 2025-02-23 7/week @ 2025-03-02 4/week @ 2025-04-13 163/week @ 2025-04-20

167 downloads per month

MIT/Apache

43KB
266 lines

bevy_2dviewangle

crates.io docs.rs dependency status pipeline status

Gitlab Github

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

Quickstart

// Struct to store sprite sheet
#[derive(View2dCollection, 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 View2dActor, Entity)>,
    mut action_event: EventWriter<ViewChanged>,
) {
    for (mut act, e) in actors.iter_mut() {
        act.action = ActionMyAssets::Idle;
        act.angle = Angle::Right;
        action_event.write(ViewChanged { entity: e });
    }
}

Please see in examples for more detail.

This plugin can work with bevy_asset_loader too:

#[derive(AssetCollection, View2dCollection, 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.16 0.10
0.15 0.9
0.14 0.7-0.8
0.13 0.2-0.6
0.12 0.1

Dependencies

~40–71MB
~1M SLoC