Sprite
Sprite
Represents a sprite for drawing to the screen.
A sprite is simply a list of bytes that are either encoded with 1 bit per pixel BPP1
or 2 bits per pixel BPP2
.
SubRegion
A subregion of a Sprite
new : { data : List U8, bpp : [ BPP1, BPP2 ], width : U32, height : U32 } -> Sprite
Create a Sprite
to be drawn or blit to the screen.
fruitSprite = Sprite.new { data: [0x00, 0xa0, 0x02, 0x00, 0x0e, 0xf0, 0x36, 0x5c, 0xd6, 0x57, 0xd5, 0x57, 0x35, 0x5c, 0x0f, 0xf0], bpp: BPP2, width: 8, height: 8, }
blit : Sprite, { x : I32, y : I32, flags ? List [ FlipX, FlipY, Rotate ] } -> Task {} *
Draw a Sprite
to the framebuffer.
{} <- Sprite.blit fruitSprite { x: 0, y: 0, flags: [FlipX, Rotate] } |> Task.await
sub : Sprite, SubRegion -> Result Sprite [OutOfBounds]
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
.
subSpriteResult = Sprite.sub sprite { srcX: 20, srcY: 0, width: 20, height: 20 }
Note: If your program should never generate an invalid subregion,
subOrCrash
enables avoiding the result and simpler code.
subOrCrash : 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.
subSprite = Sprite.subOrCrash sprite { srcX: 20, srcY: 0, width: 20, height: 20 }
Warning: Will crash if the subregion is not contained within the sprite.