|
|
|
|
@ -9,7 +9,6 @@ fn main() {
|
|
|
|
|
},))
|
|
|
|
|
.add_systems(Startup, spawn_background)
|
|
|
|
|
.add_systems(Update, move_camera)
|
|
|
|
|
.add_systems(Update, parallax_gizmos)
|
|
|
|
|
.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -17,43 +16,55 @@ fn spawn_background(
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
mut meshes: ResMut<Assets<Mesh>>,
|
|
|
|
|
mut materials: ResMut<Assets<ColorMaterial>>,
|
|
|
|
|
server: Res<AssetServer>,
|
|
|
|
|
) {
|
|
|
|
|
let mesh = Mesh2d(meshes.add(Circle::new(1.0)));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 1.1"),
|
|
|
|
|
Name::new("Depth: 1.0"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, 0.0)).with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(RED))),
|
|
|
|
|
ParallaxDepth(1.1),
|
|
|
|
|
Mesh2d(meshes.add(Circle::new(1.0))),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
|
texture: Some(server.load("bevy.png")),
|
|
|
|
|
color: RED.into(),
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
ParallaxDepth(1.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("1.1".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 2.1"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -1.0)).with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(GREEN))),
|
|
|
|
|
ParallaxDepth(2.1),
|
|
|
|
|
Name::new("Depth: 2.0"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -1.0)).with_scale(Vec3::splat(25.0)),
|
|
|
|
|
Mesh2d(meshes.add(Circle::new(2.0))),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
|
texture: Some(server.load("bevy.png")),
|
|
|
|
|
color: GREEN.into(),
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
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.1"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -2.0)).with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(BLUE))),
|
|
|
|
|
ParallaxDepth(4.1),
|
|
|
|
|
Name::new("Depth: 4.0"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -2.0)).with_scale(Vec3::splat(12.5)),
|
|
|
|
|
Mesh2d(meshes.add(Circle::new(4.0))),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
|
texture: Some(server.load("bevy.png")),
|
|
|
|
|
color: BLUE.into(),
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
ParallaxDepth(4.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("4.1".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
commands.spawn((
|
|
|
|
|
Name::new("Depth: 8.1"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -3.0)).with_scale(Vec3::splat(50.0)),
|
|
|
|
|
mesh.clone(),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial::from_color(YELLOW))),
|
|
|
|
|
ParallaxDepth(8.1),
|
|
|
|
|
Name::new("Depth: 8.0"),
|
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, -3.0)).with_scale(Vec3::splat(6.25)),
|
|
|
|
|
Mesh2d(meshes.add(Circle::new(8.0))),
|
|
|
|
|
MeshMaterial2d(materials.add(ColorMaterial {
|
|
|
|
|
texture: Some(server.load("bevy.png")),
|
|
|
|
|
color: YELLOW.into(),
|
|
|
|
|
..default()
|
|
|
|
|
})),
|
|
|
|
|
ParallaxDepth(8.0),
|
|
|
|
|
Visibility::Inherited,
|
|
|
|
|
children![(Text2d("8.1".into()), Transform::from_xyz(0.0, 35.0, 0.0))],
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -70,18 +81,3 @@ fn move_camera(mut t: Single<&mut Transform, With<Camera2d>>, keys: Res<ButtonIn
|
|
|
|
|
t.translation.y += 5.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parallax_gizmos(mut gizmos: Gizmos, q: Query<&Transform, With<ParallaxDepth>>) {
|
|
|
|
|
// Closest to camera
|
|
|
|
|
// Parallax(1)
|
|
|
|
|
q.iter().for_each(|t| {
|
|
|
|
|
gizmos
|
|
|
|
|
.grid_2d(
|
|
|
|
|
t.translation.truncate(),
|
|
|
|
|
UVec2::new(5, 5),
|
|
|
|
|
Vec2::splat(10.),
|
|
|
|
|
MAGENTA,
|
|
|
|
|
)
|
|
|
|
|
.outer_edges();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|