From e803d0bf4c7ccc997c1e011b6dd5837ad2d1b653 Mon Sep 17 00:00:00 2001 From: Arc-blroth <45273859+Arc-blroth@users.noreply.github.com> Date: Thu, 18 Aug 2022 12:25:09 -0700 Subject: [PATCH 1/4] update bevy -> 0.8 and benimator -> 4.0.0-rc.1 --- Cargo.toml | 4 +-- assets/sprites/hello.aseprite | Bin 2039 -> 2069 bytes examples/animated/main.rs | 50 ++++++++++++++++++++++++++-------- src/benimator.rs | 6 ++-- src/loader.rs | 4 +-- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 82062eb..31dd7c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = "0.7" +bevy = "0.8" asefile = "0.3.5" anyhow = "1.0" bevy_ecs_tilemap = { version = "0.6.0", optional = true } -benimator = { version = "3.5.0", optional = true} +benimator = { version = "4.0.0-rc.1", optional = true} [profile.dev.package."*"] opt-level = 2 diff --git a/assets/sprites/hello.aseprite b/assets/sprites/hello.aseprite index c9c7f3e9aecfbcc8ebd7fbcbcb0d66abf2eb5195..2901ec5c398a61c75966b7c879782e1d264948ac 100644 GIT binary patch delta 68 zcmey)KUIK9lw%@O9pllBjr`1du?!3h5(>;f5(b!H3<%B5;98biR9TXdnU}7(c>!}c F3jm0j3$OqH delta 38 ocmbO#@SUIOJNrbYI>zN28~K?9>=_ssBovr{Bm`{U#~jWA0KwG=0RR91 diff --git a/examples/animated/main.rs b/examples/animated/main.rs index 14a828d..d5eb796 100644 --- a/examples/animated/main.rs +++ b/examples/animated/main.rs @@ -1,24 +1,31 @@ use std::path::Path; -use bevy::{input::system::exit_on_esc_system, prelude::*, sprite::SpriteSheetBundle}; +use bevy::{prelude::*, reflect::TypeUuid, sprite::SpriteSheetBundle}; use bevy_ase::{ self, asset::{Animation, AseAsset}, loader::{self, Loader}, }; +#[derive(TypeUuid, Deref)] +#[uuid = "33fd3d9b-dd1e-4d38-9b82-30751b29c72c"] +pub struct SpriteSheetAnimation(benimator::Animation); + +#[derive(Default, Component, Deref, DerefMut)] +pub struct SpriteSheetAnimationState(benimator::State); + fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugin(loader::AseLoaderDefaultPlugin) - .add_plugin(benimator::AnimationPlugin::default()) - .add_system(exit_on_esc_system.system()) + .add_asset::() .add_state(AppState::Loading) - .add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites.system())) + .add_system_set(SystemSet::on_enter(AppState::Loading).with_system(load_sprites)) .add_system_set( - SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites.system()), + SystemSet::on_update(AppState::Loading).with_system(check_loading_sprites), ) - .add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_sprites.system())) + .add_system_set(SystemSet::on_enter(AppState::Game).with_system(spawn_sprites)) + .add_system_set(SystemSet::on_update(AppState::Game).with_system(animate)) .run() } @@ -47,11 +54,11 @@ pub fn check_loading_sprites(mut state: ResMut>, ase_loader: Res pub fn spawn_sprites( mut commands: Commands, animations: Res>, - mut sprite_sheet_animations: ResMut>, + mut sprite_sheet_animations: ResMut>, ) { commands.spawn_bundle({ - let mut b = OrthographicCameraBundle::new_2d(); - b.orthographic_projection.scale = 1.0 / 3.0; // scale to 3x + let mut b = Camera2dBundle::default(); + b.projection.scale = 1.0 / 3.0; // scale to 3x b }); @@ -59,8 +66,8 @@ pub fn spawn_sprites( for (idx, (_id, anim)) in anims { let texture_atlas = anim.atlas(); // The "benimator" feature provides a From implementation to convert animations. - let anim: benimator::SpriteSheetAnimation = anim.into(); - let anim_handle = sprite_sheet_animations.add(anim); + let anim: benimator::Animation = anim.into(); + let anim_handle = sprite_sheet_animations.add(SpriteSheetAnimation(anim)); let x_position = idx as f32 * 50.0; commands @@ -70,6 +77,25 @@ pub fn spawn_sprites( ..Default::default() }) .insert(anim_handle) - .insert(benimator::Play); + .insert(SpriteSheetAnimationState::default()); + } +} + +pub fn animate( + time: Res