Skip to content

Commit

Permalink
Update event example
Browse files Browse the repository at this point in the history
  • Loading branch information
Multirious committed Apr 4, 2024
1 parent 9f4b667 commit 2cd20d4
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions examples/demo/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ struct EffectPos {
boom: Vec3,
}

#[derive(Component)]
struct Triangle;

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());

let start_x = -200.;
let end_x = 200.;
let start_x = -300.;
let end_x = 300.;

commands.insert_resource(EffectPos {
trail: Vec3::new(start_x - 40., 0., 0.),
Expand All @@ -36,17 +39,19 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {

commands
.spawn((
Triangle,
SpriteBundle {
texture: asset_server.load("triangle_filled.png"),
..Default::default()
},
SpanTweenerBundle::new(secs(2.)).with_repeat(Repeat::Infinitely),
))
.with_children(|c| {
// &'static str is available as an even data but recommended to use
// dedicated custom type instead to leverage the rust type system.
// &'static str is available as an default event data but it's
// recommended to use dedicated custom type instead to leverage the
// rust type system.
c.span_tweens()
.tween_event(TweenEventData::with_data("trail"))
.tween_event(TweenEventData::with_data("bump"))
.tween(
secs(1.),
EaseFunction::ExponentialIn,
Expand All @@ -61,10 +66,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
}),
),
)
.backward(secs(0.2))
.tween_event_for(
secs(0.2),
TweenEventData::with_data("small_boom"),
)
.tween_event(TweenEventData::with_data("boom"))
.tween(
secs(1.),
EaseFunction::ExponentialOut,
EaseFunction::CircularOut,
(
ComponentTween::new(interpolate::Translation {
start: Vec3::new(end_x, 0., 0.),
Expand All @@ -86,10 +96,11 @@ fn effect_system(
mut commands: Commands,
asset_server: Res<AssetServer>,
effect_pos: Res<EffectPos>,
q_triangle: Query<&Transform, With<Triangle>>,
mut event: EventReader<TweenEvent<&'static str>>,
) {
event.read().for_each(|event| match event.data {
"trail" => {
"bump" => {
commands.spawn((
Effect,
SpriteBundle {
Expand All @@ -112,6 +123,28 @@ fn effect_system(
}),
));
}
"small_boom" => {
commands.spawn((
Effect,
SpriteBundle {
texture: asset_server.load("circle.png"),
transform: Transform::from_translation(
q_triangle.single().translation,
),
..Default::default()
},
SpanTweenerBundle::new(secs(0.1)).tween_here(),
EaseFunction::Linear,
ComponentTween::new(interpolate::Scale {
start: Vec3::new(0.5, 0.5, 0.),
end: Vec3::new(3., 3., 0.),
}),
ComponentTween::new(interpolate::SpriteColor {
start: Color::WHITE.with_a(0.2),
end: Color::WHITE.with_a(0.),
}),
));
}
"boom" => {
commands.spawn((
Effect,
Expand All @@ -121,13 +154,13 @@ fn effect_system(
..Default::default()
},
SpanTweenerBundle::new(secs(0.5)).tween_here(),
EaseFunction::ExponentialOut,
EaseFunction::QuadraticOut,
ComponentTween::new(interpolate::Scale {
start: Vec3::new(1., 1., 0.),
end: Vec3::new(15., 15., 0.),
}),
ComponentTween::new(interpolate::SpriteColor {
start: Color::WHITE,
start: Color::WHITE.with_a(0.5),
end: Color::WHITE.with_a(0.),
}),
));
Expand Down

0 comments on commit 2cd20d4

Please sign in to comment.