From 8374d87d458a85bf2f0cff0372e18d64afd70df3 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Mon, 18 Aug 2025 12:30:07 -0700 Subject: [PATCH] And with that... it is working flawlessly --- examples/parallax.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/parallax.rs b/examples/parallax.rs index 6b95dea..5ae8e3b 100644 --- a/examples/parallax.rs +++ b/examples/parallax.rs @@ -20,40 +20,38 @@ fn spawn_background( mut materials: ResMut>, ) { 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> 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