#bevy-plugin #bevy #texture #view #switch #angle #base

bevy_2dviewangle

Bevy 插件,用于更轻松地在视图角度之间切换纹理

17 个版本 (8 个破坏性更新)

0.8.0 2024 年 8 月 7 日
0.7.1 2024 年 7 月 17 日
0.6.0 2024 年 5 月 27 日
0.2.0 2024 年 2 月 26 日

#326 in 游戏开发

Download history 141/week @ 2024-04-28 35/week @ 2024-05-05 128/week @ 2024-05-12 138/week @ 2024-05-19 173/week @ 2024-05-26 11/week @ 2024-06-02 8/week @ 2024-06-09 1/week @ 2024-06-16 96/week @ 2024-06-30 90/week @ 2024-07-07 105/week @ 2024-07-14 9/week @ 2024-07-21 35/week @ 2024-07-28 124/week @ 2024-08-04 8/week @ 2024-08-11

每月 185 次下载

MIT/Apache

36KB
284

bevy_2dviewangle

crates.io docs.rs dependency status pipeline status

Bevy 插件,用于更轻松地管理和切换基于视图角度的纹理。

快速入门

// 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 = AngleMyAssets::Right;
        action_event.send(ViewChanged { entity: e });
    }
}

有关更多详细信息,请参阅示例

此插件也可以与bevy_asset_loader一起使用

#[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

兼容的 Bevy 版本

bevy bevy_2dviewangle
0.14 0.7-0.8, 分支 master
0.13 0.2-0.6
0.12 0.1

依赖项

~36–73MB
~1.5M SLoC