pub struct Body { /* private fields */ }Expand description
A moving body that renders a clean pixel staircase instead of a zigzag.
Hold the full-precision position for game logic, advance it each frame with
move_by, and draw at draw_x /
draw_y.
The drawn pixel never differs from floor(x) /
floor(y) by more than one pixel, and that difference does
not accumulate — so collision against the exact position stays honest while
the sprite stops shimmering.
Implementations§
Source§impl Body
impl Body
Sourcepub fn new(x: f32, y: f32) -> Self
pub fn new(x: f32, y: f32) -> Self
A body at a starting position. The drawn pixel starts floored, as usual.
Sourcepub fn move_by(&mut self, dx: f32, dy: f32)
pub fn move_by(&mut self, dx: f32, dy: f32)
Advance one frame by a per-frame delta (i.e. velocity in px/frame).
The cart owns its own acceleration, friction and input handling; this just takes the resulting movement for the frame and updates both the exact position and the coherent render pixel.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Body
impl RefUnwindSafe for Body
impl Send for Body
impl Sync for Body
impl Unpin for Body
impl UnsafeUnpin for Body
impl UnwindSafe for Body
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more