Skip to content

Commit 2ef76ad

Browse files
committed
make pegs follow touch pos
1 parent c2e1479 commit 2ef76ad

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

solitaire-game/src/animation.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ impl Plugin for PegAnimation {
1717
fn build(&self, app: &mut App) {
1818
app.add_systems(Update, snap_to_board_grid);
1919
app.add_systems(Update, follow_mouse);
20+
app.add_systems(Update, follow_touch);
2021
}
2122
}
2223

@@ -59,3 +60,23 @@ fn follow_mouse(
5960
}
6061
}
6162
}
63+
64+
fn follow_touch(
65+
camera_query: Single<(&Camera, &GlobalTransform)>,
66+
mut transforms: Query<&mut Transform, With<Selected>>,
67+
touches: Res<Touches>,
68+
) {
69+
let (camera, camera_transform) = *camera_query;
70+
for touch in touches.iter() {
71+
if let Some(mut destination) = viewport_to_world(touch.position(), camera, camera_transform)
72+
{
73+
for mut transform in &mut transforms {
74+
let current_z = transform.translation.z;
75+
let destination_z = PEG_POS_RAISED;
76+
destination.z = current_z.lerp(destination_z, 0.2);
77+
transform.translation = destination;
78+
// no need to RequestRedraw, since mouse movement already triggers a wakeup
79+
}
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)