more animatoin hell
This commit is contained in:
parent
ebff0ac8ac
commit
c897a77e8d
2 changed files with 26 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
use std::{hash::Hash, time::Duration};
|
||||
|
||||
use animation::AnimBundle;
|
||||
use bevy::{prelude::*, sprite::MaterialMesh2dBundle, utils::HashMap};
|
||||
|
||||
use bevy_rapier2d::prelude::*;
|
||||
|
@ -11,13 +12,13 @@ use super::set::IngameSet;
|
|||
mod animation;
|
||||
|
||||
#[derive(Component)]
|
||||
struct Player {}
|
||||
struct Player;
|
||||
|
||||
pub(super) fn player_plugin(app: &mut App) {
|
||||
app.add_systems(OnEnter(AppState::InGame), add_player.in_set(IngameSet));
|
||||
}
|
||||
|
||||
#[derive(Hash, PartialEq, Eq, Default)]
|
||||
#[derive(Component, Hash, PartialEq, Eq, Default)]
|
||||
enum PlayerAnimations {
|
||||
#[default]
|
||||
Idle,
|
||||
|
@ -64,4 +65,16 @@ pub fn add_player(
|
|||
tex_walk,
|
||||
),
|
||||
);
|
||||
|
||||
commands.spawn((
|
||||
Player,
|
||||
AnimBundle {
|
||||
tag: PlayerAnimations::Idle,
|
||||
mgr: anims,
|
||||
},
|
||||
SpriteBundle {
|
||||
transform: Transform::from_scale(Vec3::splat(50.)),
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
|
|
@ -5,13 +5,19 @@ use bevy::utils::HashMap;
|
|||
|
||||
use std::hash::Hash;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct AnimationManager<Anim: Hash + Eq> {
|
||||
animations: HashMap<Anim, Animation>,
|
||||
#[derive(Bundle)]
|
||||
pub struct AnimBundle<Tag: Hash + Eq + Component> {
|
||||
pub tag: Tag,
|
||||
pub mgr: AnimationManager<Tag>,
|
||||
}
|
||||
|
||||
impl<Anim: Hash + Eq> AnimationManager<Anim> {
|
||||
pub fn insert(mut self, which: Anim, anim: Animation) -> Self {
|
||||
#[derive(Default, Component)]
|
||||
pub(crate) struct AnimationManager<Tag: Hash + Eq> {
|
||||
animations: HashMap<Tag, Animation>,
|
||||
}
|
||||
|
||||
impl<Tag: Hash + Eq> AnimationManager<Tag> {
|
||||
pub fn insert(mut self, which: Tag, anim: Animation) -> Self {
|
||||
self.animations.insert(which, anim);
|
||||
self
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue