Compare commits
No commits in common. '8c440317e70233971f47af420ddef882ff0361db' and 'a2367fb4f74b65b7d133f4f0e897d06a82c5e406' have entirely different histories.
8c440317e7
...
a2367fb4f7
@ -0,0 +1 @@
|
|||||||
|
*.ogg filter=lfs diff=lfs merge=lfs -text
|
||||||
@ -1,3 +1,2 @@
|
|||||||
*.ogg filter=lfs diff=lfs merge=lfs -text
|
|
||||||
*.xcf filter=lfs diff=lfs merge=lfs -text
|
|
||||||
*.png filter=lfs diff=lfs merge=lfs -text
|
*.png filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xcf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,55 +0,0 @@
|
|||||||
use games::*;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
App::new()
|
|
||||||
.add_plugins((BaseGamePlugin {
|
|
||||||
name: "parallax example".into(),
|
|
||||||
title: "Parallax".into(),
|
|
||||||
game_type: GameType::Two,
|
|
||||||
},))
|
|
||||||
.add_systems(Startup, spawn_background)
|
|
||||||
.add_systems(Update, move_camera)
|
|
||||||
.add_systems(Update, parallax_gizmos)
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn spawn_background(
|
|
||||||
mut commands: Commands,
|
|
||||||
) {
|
|
||||||
commands.spawn((Parallax(1.0), children![(Text2d("1.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
|
|
||||||
commands.spawn((Parallax(2.0), children![(Text2d("2.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
|
|
||||||
commands.spawn((Parallax(4.0), children![(Text2d("4.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
|
|
||||||
commands.spawn((Parallax(8.0), children![(Text2d("8.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))]));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn move_camera(
|
|
||||||
mut t: Single<&mut Transform, With<Camera2d>>,
|
|
||||||
keys: Res<ButtonInput<KeyCode>>,
|
|
||||||
) {
|
|
||||||
if keys.pressed(KeyCode::ArrowLeft) {
|
|
||||||
t.translation.x -= 5.0;
|
|
||||||
} else if keys.pressed(KeyCode::ArrowRight) {
|
|
||||||
t.translation.x += 5.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if keys.pressed(KeyCode::ArrowDown) {
|
|
||||||
t.translation.y -= 5.0;
|
|
||||||
} else if keys.pressed(KeyCode::ArrowUp) {
|
|
||||||
t.translation.y += 5.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn parallax_gizmos(
|
|
||||||
mut gizmos: Gizmos,
|
|
||||||
q: Query<&Transform, With<Parallax>>,
|
|
||||||
) {
|
|
||||||
// Closest to camera
|
|
||||||
// Parallax(1)
|
|
||||||
q.iter().for_each(|t| {
|
|
||||||
gizmos.grid_2d(
|
|
||||||
t.translation.truncate(),
|
|
||||||
UVec2::new(5, 5),
|
|
||||||
Vec2::splat(10.),
|
|
||||||
RED,
|
|
||||||
).outer_edges();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
use super::*;
|
|
||||||
|
|
||||||
pub struct ParallaxPlugin;
|
|
||||||
|
|
||||||
impl Plugin for ParallaxPlugin {
|
|
||||||
fn build(&self, app: &mut App) {
|
|
||||||
app.add_systems(Update, move_parallax_items.run_if(any_component_changed::<Transform>));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
#[require(Transform)]
|
|
||||||
pub struct Parallax(pub f32);
|
|
||||||
|
|
||||||
fn move_parallax_items(
|
|
||||||
mut q: Query<(&mut Transform, &Parallax), Without<Camera2d>>,
|
|
||||||
cam_t: Single<&Transform, With<Camera2d>>,
|
|
||||||
) {
|
|
||||||
let base = cam_t.translation.truncate();
|
|
||||||
|
|
||||||
q.iter_mut().for_each(|(mut t, p)| {
|
|
||||||
let val = base * (1.0 - (1.0 / p.0));
|
|
||||||
t.translation.x = val.x;
|
|
||||||
t.translation.y = val.y;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue