pub struct Sprite<'a> { /* private fields */ }Expand description
A 1-bps or 2-bps bitmap drawable on screen
Sprites
WASM-4 natively supports sprites with the functions wasm4fun_core::blit
and wasm4fun_core::blit_sub.
Instead of passing sprite information as separate arguments, this structure
conveniently wraps them in a single place.
It also makes it easier to apply transformations using a SpriteViewImpl.
They can be generated by PNG images with the command w4 png2src --rust.
use wasm4fun_graphics::Sprite;
const CAR_WIDTH: u32 = 16;
const CAR_HEIGHT: u32 = 16;
const CAR_FLAGS: u32 = 1; // BLIT_2BPP
const CAR: [u8; 256] = [0; 256];
let car = Sprite::new(CAR_WIDTH, CAR_HEIGHT, CAR_FLAGS, &CAR);
// Draw car to screen
car.blit(10, 40);
// Create a clipped view of the original sprite
let clip = car.clip(0, 0, 8, 8);
clip.blit(10, 40);Implementations§
Source§impl<'a> Sprite<'a>
impl<'a> Sprite<'a>
Sourcepub const fn new(width: u32, height: u32, flags: u32, data: &'a [u8]) -> Self
pub const fn new(width: u32, height: u32, flags: u32, data: &'a [u8]) -> Self
Create a new sprite
Sourcepub const fn rotate(&self, rotation: Rotation) -> SpriteViewImpl<'_>
pub const fn rotate(&self, rotation: Rotation) -> SpriteViewImpl<'_>
Apply a rotation to the sprite
Sourcepub fn flip_horizontally(&self, flip_horizontally: bool) -> SpriteViewImpl<'_>
pub fn flip_horizontally(&self, flip_horizontally: bool) -> SpriteViewImpl<'_>
Flip the sprite horizontally
Sourcepub const fn flip_vertically(&self, flip_vertically: bool) -> SpriteViewImpl<'_>
pub const fn flip_vertically(&self, flip_vertically: bool) -> SpriteViewImpl<'_>
Flip the sprite vertically
Trait Implementations§
Source§impl<'a> From<&'a Sprite<'a>> for SpriteViewImpl<'a>
impl<'a> From<&'a Sprite<'a>> for SpriteViewImpl<'a>
Source§impl<'a> SpriteView<'a> for Sprite<'a>
impl<'a> SpriteView<'a> for Sprite<'a>
Source§fn rotate(&'a self, rotation: Rotation) -> SpriteViewImpl<'a>
fn rotate(&'a self, rotation: Rotation) -> SpriteViewImpl<'a>
Apply a rotation to the sprite view
Source§fn flip_horizontally(&'a self, flip_horizontally: bool) -> SpriteViewImpl<'a>
fn flip_horizontally(&'a self, flip_horizontally: bool) -> SpriteViewImpl<'a>
Flip the sprite view horizontally
Source§fn flip_vertically(&'a self, flip_vertically: bool) -> SpriteViewImpl<'a>
fn flip_vertically(&'a self, flip_vertically: bool) -> SpriteViewImpl<'a>
Flip the sprite view vertically
Auto Trait Implementations§
impl<'a> Freeze for Sprite<'a>
impl<'a> RefUnwindSafe for Sprite<'a>
impl<'a> Send for Sprite<'a>
impl<'a> Sync for Sprite<'a>
impl<'a> Unpin for Sprite<'a>
impl<'a> UnsafeUnpin for Sprite<'a>
impl<'a> UnwindSafe for Sprite<'a>
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