Sprite
:= {
data : List(U8),
bpp : [BPP1, BPP2],
stride : U32,
region : { src_x : U32, src_y : U32, width : U32, height : U32 },
}
Sprites for drawing to the WASM-4 framebuffer.
A Sprite is simply a list of bytes encoded with either 1 bit per pixel (BPP1)
or 2 bits per pixel (BPP2), along with information about how to read the
pixel data.
Draw a Sprite to the framebuffer.
Sprite.blit!(fruit_sprite, { x: 0, y: 0, flags: Sprite.Flags.default().flip_x().rotate() })
Creates a Sprite referencing a subregion of the current Sprite.
This will return an error if the subregion does not fit in the current Sprite.
sub_sprite_result = Sprite.sub(sprite, { src_x: 20, src_y: 0, width: 20, height: 20 })
Note: If your program should never generate an invalid subregion,
sub_or_crash enables avoiding the result and simpler code.
sub_or_crash : Sprite, SubRegion -> Sprite
Equivalent to the sub function, but will crash on error.
This is really useful for static sprite sheet data that needs subSprites extracted.
sub_sprite = Sprite.sub_or_crash(sprite, { src_x: 20, src_y: 0, width: 20, height: 20 })
Warning: Will crash if the subregion is not contained within the sprite.
Flags
Sprite.Flags :: # (opaque)
A subregion of a Sprite.