|
|
|
@ -10,7 +10,6 @@ fn main() {
|
|
|
|
.add_systems(Startup, spawn_background)
|
|
|
|
.add_systems(Startup, spawn_background)
|
|
|
|
.add_systems(Update, move_camera)
|
|
|
|
.add_systems(Update, move_camera)
|
|
|
|
.add_systems(Update, parallax_gizmos)
|
|
|
|
.add_systems(Update, parallax_gizmos)
|
|
|
|
.add_systems(Update, move_parallax_items)
|
|
|
|
|
|
|
|
.run();
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,33 +18,42 @@ fn spawn_background(
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let mesh = Mesh2d(meshes.add(Circle::new(50.0)));
|
|
|
|
let mesh = Mesh2d(meshes.add(Circle::new(1.0)));
|
|
|
|
let material = MeshMaterial2d(materials.add(ColorMaterial::from_color(RED)));
|
|
|
|
let material = MeshMaterial2d(materials.add(ColorMaterial::from_color(RED)));
|
|
|
|
|
|
|
|
let transform = Transform::default().with_scale(Vec3::splat(50.0));
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
|
|
|
|
Name::new("Depth: 1"),
|
|
|
|
|
|
|
|
transform,
|
|
|
|
mesh.clone(),
|
|
|
|
mesh.clone(),
|
|
|
|
material.clone(),
|
|
|
|
material.clone(),
|
|
|
|
Parallax(1.0),
|
|
|
|
ParallaxDepth(1.0),
|
|
|
|
Visibility::Inherited,
|
|
|
|
Visibility::Inherited,
|
|
|
|
children![(Text2d("1.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
children![(Text2d("1.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
|
|
|
|
Name::new("Depth: 2"),
|
|
|
|
|
|
|
|
transform,
|
|
|
|
mesh.clone(),
|
|
|
|
mesh.clone(),
|
|
|
|
material.clone(),
|
|
|
|
material.clone(),
|
|
|
|
Parallax(2.0),
|
|
|
|
ParallaxDepth(2.0),
|
|
|
|
Visibility::Inherited,
|
|
|
|
Visibility::Inherited,
|
|
|
|
children![(Text2d("2.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
children![(Text2d("2.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
|
|
|
|
Name::new("Depth: 4"),
|
|
|
|
|
|
|
|
transform,
|
|
|
|
mesh.clone(),
|
|
|
|
mesh.clone(),
|
|
|
|
material.clone(),
|
|
|
|
material.clone(),
|
|
|
|
Parallax(4.0),
|
|
|
|
ParallaxDepth(4.0),
|
|
|
|
Visibility::Inherited,
|
|
|
|
Visibility::Inherited,
|
|
|
|
children![(Text2d("4.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
children![(Text2d("4.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
commands.spawn((
|
|
|
|
commands.spawn((
|
|
|
|
|
|
|
|
Name::new("Depth: 8"),
|
|
|
|
|
|
|
|
transform,
|
|
|
|
mesh.clone(),
|
|
|
|
mesh.clone(),
|
|
|
|
material.clone(),
|
|
|
|
material.clone(),
|
|
|
|
Parallax(8.0),
|
|
|
|
ParallaxDepth(8.0),
|
|
|
|
Visibility::Inherited,
|
|
|
|
Visibility::Inherited,
|
|
|
|
children![(Text2d("8.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
children![(Text2d("8.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
@ -65,7 +73,7 @@ fn move_camera(mut t: Single<&mut Transform, With<Camera2d>>, keys: Res<ButtonIn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn parallax_gizmos(mut gizmos: Gizmos, q: Query<&Transform, With<Parallax>>) {
|
|
|
|
fn parallax_gizmos(mut gizmos: Gizmos, q: Query<&Transform, With<ParallaxDepth>>) {
|
|
|
|
// Closest to camera
|
|
|
|
// Closest to camera
|
|
|
|
// Parallax(1)
|
|
|
|
// Parallax(1)
|
|
|
|
q.iter().for_each(|t| {
|
|
|
|
q.iter().for_each(|t| {
|
|
|
|
@ -79,16 +87,3 @@ fn parallax_gizmos(mut gizmos: Gizmos, q: Query<&Transform, With<Parallax>>) {
|
|
|
|
.outer_edges();
|
|
|
|
.outer_edges();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Move to src/parallax.rs
|
|
|
|
|
|
|
|
fn move_parallax_items(
|
|
|
|
|
|
|
|
mut q: Query<(Entity, &ViewVisibility, &mut ParallaxRepeatIteration), (With<Parallax>, Changed<ViewVisibility>)>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
q.iter_mut().for_each(|(e, vis, mut pri)| {
|
|
|
|
|
|
|
|
warn!("{e} {:?}", vis.get());
|
|
|
|
|
|
|
|
if !vis.get() {
|
|
|
|
|
|
|
|
pri.0 += 1;
|
|
|
|
|
|
|
|
todo!("Works when moving camera right, make it work left too");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|