simple transform animation
This commit is contained in:
parent
badc59c239
commit
e17c712ec6
4 changed files with 35 additions and 1 deletions
10
src/animation/mod.rs
Normal file
10
src/animation/mod.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use bevy::{app::Update, prelude::Plugin};
|
||||
pub mod transform;
|
||||
|
||||
pub struct AnimationPlugin;
|
||||
|
||||
impl Plugin for AnimationPlugin {
|
||||
fn build(&self, app: &mut bevy::app::App) {
|
||||
app.add_systems(Update, transform::transform_animation);
|
||||
}
|
||||
}
|
||||
20
src/animation/transform.rs
Normal file
20
src/animation/transform.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct AnimatedTransform {
|
||||
pub translation: Vec3,
|
||||
}
|
||||
|
||||
impl AnimatedTransform {
|
||||
pub fn from_xyz(x: f32, y: f32, z: f32) -> Self {
|
||||
AnimatedTransform {
|
||||
translation: Vec3 { x, y, z },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn transform_animation(query: Query<(&mut Transform, &AnimatedTransform)>) {
|
||||
for (mut transform, anim_transform) in query {
|
||||
transform.translation = transform.translation.lerp(anim_transform.translation, 0.5);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::animation::transform::AnimatedTransform;
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub mod drag;
|
||||
|
|
@ -41,7 +42,7 @@ fn hand_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
}
|
||||
|
||||
fn card_arrange(
|
||||
query: Query<(Entity, &mut Transform, &Sprite, &ChildOf), With<Card>>,
|
||||
query: Query<(Entity, &mut AnimatedTransform, &Sprite, &ChildOf), With<Card>>,
|
||||
hand: Single<(Entity, &Children), With<Hand>>,
|
||||
assets: Res<Assets<Image>>,
|
||||
) {
|
||||
|
|
@ -67,6 +68,7 @@ fn card_add(
|
|||
commands.spawn((
|
||||
Sprite::from_image(card_image.0.clone()),
|
||||
Transform::from_xyz(0., 0., 0.),
|
||||
AnimatedTransform::from_xyz(0., 0., 0.),
|
||||
Card,
|
||||
ChildOf(hand.entity()),
|
||||
));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use bevy::{audio::Volume, prelude::*};
|
||||
|
||||
mod animation;
|
||||
mod buttons;
|
||||
mod card;
|
||||
mod dev_tools;
|
||||
|
|
@ -13,6 +14,7 @@ fn main() {
|
|||
card::CardPlugin,
|
||||
dev_tools::DevToolsPlugin,
|
||||
buttons::ButtonPlugin,
|
||||
animation::AnimationPlugin,
|
||||
))
|
||||
.add_systems(Startup, setup)
|
||||
.run();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue