Crates.io | bevy_2dviewangle |
lib.rs | bevy_2dviewangle |
version | 0.4.2 |
source | src |
created_at | 2024-01-26 09:23:16.208264 |
updated_at | 2024-05-04 07:48:23.173225 |
description | Bevy plugin for easier to switch texture base on view angles |
homepage | |
repository | https://gitlab.com/kimtinh/bevy-2dviewangle |
max_upload_size | |
id | 1115343 |
size | 114,011 |
Bevy plugin to easier to switch texture base on view angles. Currently, support 8 view angles:
Add plugin.
App::new()
...
.add_plugins(View2DAnglePlugin)
...
Declare texture map with each actor and action with view angle.
// Struct to load spritesheet
#[derive(ActorsTexturesCollection, Default)]
struct MyAssets {
#[textureview(actor = 0, action = 0, angle = "front", handle = "image")]
pub idle_front: Handle<Image>,
// If not specify actor/action, the previous value will be used
#[textureview(angle = "back", handle = "image")]
pub idle_back: Handle<Image>,
#[textureview(angle = "front", handle = "atlas_layout")]
pub layout: Handle<TextureAtlasLayout>,
// If angle is any, other angle which has not been defined will use this value
#[textureview(angle = "any", handle = "atlas_layout")]
pub 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 = new_action;
act.angle = new_direction;
// Send event to change to sprite sheet to another view
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 = 0, action = 0, angle = "front", handle = "image")]
pub idle_front: Handle<Image>,
#[asset(path = "frog_idle_back.png")]
#[textureview(angle = "back", handle = "image")]
pub idle_back: Handle<Image>,
#[asset(path = "frog_idle_left.png")]
#[textureview(angle = "left", handle = "image")]
pub idle_left: Handle<Image>,
#[asset(texture_atlas_layout(tile_size_x = 16., tile_size_y = 16., columns = 1, rows = 3))]
#[textureview(angle = "any", handle = "atlas_layout")]
pub front_layout: Handle<TextureAtlasLayout>,
}
Please see LICENSE.
bevy | bevy_2dviewangle |
---|---|
0.13 | 0.2-0.4, branch master |
0.12 | 0.1 |