Bevy Version: | 0.10 | (current) |
---|
2D objects not displaying
Bevy's 2D coordinate space is set up so that your background can be at Z=0.0, and other 2D objects can be layered at positive +Z coordinates above that.
Therefore, to see your scene, the camera needs to be placed far away, at a large +Z coordinate, looking towards -Z.
If you are overriding the camera transform / creating your
own transform, you need to do this! The default transform (with Z=0.0)
will place the camera so that your sprites (at positive +Z coordinates)
would be behind the camera, and you wouldn't see them! You need to
either set a large Z coordinate, or preserve/copy the Z value from the
Transform
that is generated by Bevy's builtin Bundle
constructor (Camera2dBundle::default()
).
By default, when you create a 2D camera using Bevy's built-in Bundle
constructor, Bevy sets the camera Transform
to have Z=999.9. This is close to
the default clipping plane (visible range of Z axis), which is set to 1000.0.
// ✗ INCORRECT: we are creating a new transform with the given rotation
// it does not have the correct Z,
// because it overrides the Transform from the bundle default
commands.spawn(Camera2dBundle {
transform: Transform::from_rotation(Quat::from_rotation_z(30.0f32.to_radians())),
..Default::default()
});
// ✓ OKAY: we can set the XYZ position ourselves.
// Z=999.9 is what Bevy's default uses.
commands.spawn(Camera2dBundle {
transform: Transform::from_xyz(0.0, 0.0, 999.9)
.with_rotation(Quat::from_rotation_z(30.0f32.to_radians())),
..Default::default()
});
// ✓ OKAY: we can create the bundle in a `mut` variable,
// and then modify only what we care about
// This way, Bevy's defaults remain intact
let mut my_camera = Camera2dBundle::default();
my_camera.transform.rotation = Quat::from_rotation_z(30.0f32.to_radians());
commands.spawn(my_camera);