|
|
|
|
@ -20,40 +20,38 @@ fn spawn_background(
|
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
|
) {
|
|
|
|
|
let mesh = Mesh2d(meshes.add(Circle::new(1.0)));
|
|
|
|
|
let material = MeshMaterial2d(materials.add(ColorMaterial::from_color(RED)));
|
|
|
|
|
let transform = Transform::default().with_scale(Vec3::splat(50.0));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 1"),
|
|
|
|
|
transform,
|
|
|
|
|
Transform::default().with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
material.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(RED))),
|
|
|
|
|
ParallaxDepth(1.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("1.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 2"),
|
|
|
|
|
transform,
|
|
|
|
|
Transform::default().with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
material.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))),
|
|
|
|
|
ParallaxDepth(2.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("2.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 4"),
|
|
|
|
|
transform,
|
|
|
|
|
Transform::default().with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
material.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(BLUE))),
|
|
|
|
|
ParallaxDepth(4.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("4.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 8"),
|
|
|
|
|
transform,
|
|
|
|
|
Transform::default().with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
material.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(YELLOW))),
|
|
|
|
|
ParallaxDepth(8.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("8.0".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
@ -83,7 +81,7 @@ fn parallax_gizmos(mut gizmos: Gizmos, q: Query<&Transform, With<ParallaxDepth>>
|
|
|
|
|
t.translation.truncate(),
|
|
|
|
|
UVec2::new(5, 5),
|
|
|
|
|
Vec2::splat(10.),
|
|
|
|
|
RED,
|
|
|
|
|
MAGENTA,
|
|
|
|
|
)
|
|
|
|
|
.outer_edges();
|
|
|
|
|
});
|
|
|
|
|
@ -112,8 +110,8 @@ fn wrap_parallax_items(
|
|
|
|
|
info!("The item is not visible");
|
|
|
|
|
|
|
|
|
|
// Get the total size (window + scale)
|
|
|
|
|
let total_size = window_size_in_world_space + t.scale.truncate();
|
|
|
|
|
info!("Window size: {:?} | Object size: {:?}", window_size_in_world_space, t.scale().truncate());
|
|
|
|
|
let total_size = window_size_in_world_space + (t.scale.truncate() * 2.0);
|
|
|
|
|
info!("Window size: {:?} | Object size: {:?}", window_size_in_world_space, t.scale.truncate());
|
|
|
|
|
info!("Total size: {:?}", total_size);
|
|
|
|
|
|
|
|
|
|
// Double check that item is out of bounds
|
|
|
|
|
@ -121,6 +119,7 @@ fn wrap_parallax_items(
|
|
|
|
|
let out_of_bounds = (total_size / 2.0) - bounds_check;
|
|
|
|
|
info!("Bounds check {:?}", bounds_check);
|
|
|
|
|
info!("Out of bounds: {:?}", out_of_bounds);
|
|
|
|
|
info!("Starting position: {:?}", t.translation);
|
|
|
|
|
if out_of_bounds.x < 0.0 {
|
|
|
|
|
info!("Object is actually out of bounds horizontally");
|
|
|
|
|
// determine if should move to the left or right relative to camera
|
|
|
|
|
|