pub struct Parallax(/* private fields */);Expand description
How much of the camera’s motion a layer takes.
1.0 is fixed in the world, 0.0 is pinned to the camera. Values between
are the usual parallax; values outside are legal and occasionally wanted — a
factor above 1 runs ahead of the camera, which is how a foreground
element sweeps past faster than the ground.
use crcbl_render::Parallax;
// A camera 100 units to the right. Each layer keeps the share of that
// movement it did *not* take: the hills drift by half, the HUD by all of it
// (so it does not move on screen), the world by none.
let hills = Parallax::new(0.5).expect("0.5 is finite");
assert_eq!(hills.offset([100.0, 0.0]), [50.0, 0.0]);
assert_eq!(Parallax::CAMERA.offset([100.0, 0.0]), [100.0, 0.0]);
assert_eq!(Parallax::WORLD.offset([100.0, 0.0]), [0.0, 0.0]);Deliberately not PartialOrd: a layer’s depth is where it sits in its
LayerStack, not how much parallax it takes, and the two disagree the
moment a HUD is added.
Implementations§
Source§impl Parallax
impl Parallax
Sourcepub fn new(factor: f32) -> Option<Self>
pub fn new(factor: f32) -> Option<Self>
A factor of factor.
None for anything not finite. A NaN factor would put every sprite on
the layer at a NaN world position, which draws nothing at all and looks
exactly like a renderer that stopped working; refusing it here is one
branch, at the only point where a computed factor enters the system.
Trait Implementations§
impl Copy for Parallax
Source§impl Default for Parallax
impl Default for Parallax
Source§fn default() -> Self
fn default() -> Self
Parallax::WORLD: a layer nobody said anything about is part of the
world, which is the answer that makes an unconfigured stack behave like
no stack at all.