Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
Provides a canvas to paint with low memory requirements.
The WSG Canvas system is a simple way of combining wsgs together to create a single sprite. Why is this useful? Well, it was initially designed for the swadgesonas, which would require loading a lot of individual WSGs and leaving them loaded, which would be pretty memory intensive. Instead, this canvas system allows for a WSG to be created once, and all the other WSGs applied over it are only loaded when the data is needed, and then immediately discarded. This is a much more efficient way to store swadgesonas, and will allow many of them to be on-screen at once.
Step one is to load up a canvas. Use canvasBlankInit() to create a blank canvas on which to paint, or load a normal WSG. Just note that any changes you make cannot be revered without re-initializing the WSG.
Next, use canvasDraw() to put WSGs onto the canvas. You can rotate, flip in both x and y, and position the WSG however you like on the canvas. Pixels outside of the boundaries of the canvas will be discarded, and transparent pixels will leave the color underneath to show through, allowing for complex layering.
Palettes are also supported, so things like custom hair colors can be applied without having to rely on a drawing function further down the line.
Two additional "simple" versions have been provided for when rotation and flipping aren't required.
Lastly, call freeWsg() when done with the canvas, just like any other WSG.
The canvas can be used like any WSG, so all wsg drawing functions work on it once it has been created.
Go to the source code of this file.
Functions | |
void | canvasBlankInit (wsg_t *canvas, int width, int height, paletteColor_t startColor, bool spiRam) |
Initializes a blank canvas to the dimensions and color provided. | |
void | canvasDrawSimple (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY) |
Draws a image to the canvas at the specified coordinates relative to the canvas. | |
void | canvasDrawSimplePal (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, wsgPalette_t *pal) |
Draws a image to the canvas at the specified coordinates relative to the canvas and applies a palette. | |
void | canvasDraw (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, bool flipX, bool flipY, int32_t rotateDeg) |
Draws an image to the canvas at a specified angle. | |
void | canvasDrawPal (wsg_t *canvas, cnfsFileIdx_t image, int startX, int startY, bool flipX, bool flipY, int32_t rotateDeg, wsgPalette_t *pal) |
Draws an image to the canvas at a specified angle. | |
void canvasBlankInit | ( | wsg_t * | canvas, |
int | width, | ||
int | height, | ||
paletteColor_t | startColor, | ||
bool | spiRam ) |
Initializes a blank canvas to the dimensions and color provided.
canvas | WSG to save the canvas too. Use a standard wsg_t and provide the pointer |
width | Width in pixels of the desired canvas |
height | Height in pixels of the desired canvas |
startColor | The initial color. Can be any paletteColor_t including cTransparent |
spiRam | Whether or not to load the pixel data into SPIRAM. |
void canvasDrawSimple | ( | wsg_t * | canvas, |
cnfsFileIdx_t | image, | ||
int | startX, | ||
int | startY ) |
Draws a image to the canvas at the specified coordinates relative to the canvas.
canvas | WSG to save changes to. Will work with any WSG, cannot be reverted |
image | New cnfsFileIdx_t to apply to the canvas |
startX | X position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
startY | Y position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
void canvasDrawSimplePal | ( | wsg_t * | canvas, |
cnfsFileIdx_t | image, | ||
int | startX, | ||
int | startY, | ||
wsgPalette_t * | pal ) |
Draws a image to the canvas at the specified coordinates relative to the canvas and applies a palette.
canvas | WSG to save changes to. Will work with any WSG, cannot be reverted |
image | New cnfsFileIdx_t to apply to the canvas |
startX | X position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
startY | Y position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
pal | Palette data to use to transform the image |
void canvasDraw | ( | wsg_t * | canvas, |
cnfsFileIdx_t | image, | ||
int | startX, | ||
int | startY, | ||
bool | flipX, | ||
bool | flipY, | ||
int32_t | rotateDeg ) |
Draws an image to the canvas at a specified angle.
canvas | WSG to save changes to. Will work with any WSG, cannot be reverted |
image | New cnfsFileIdx_t to apply to the canvas |
startX | X position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
startY | Y position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
flipX | Flips applied image in the x direction |
flipY | Flips applied image in the Y direction |
rotateDeg | Angle to draw the image at |
void canvasDrawPal | ( | wsg_t * | canvas, |
cnfsFileIdx_t | image, | ||
int | startX, | ||
int | startY, | ||
bool | flipX, | ||
bool | flipY, | ||
int32_t | rotateDeg, | ||
wsgPalette_t * | pal ) |
Draws an image to the canvas at a specified angle.
canvas | WSG to save changes to. Will work with any WSG, cannot be reverted |
image | New cnfsFileIdx_t to apply to the canvas |
startX | X position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
startY | Y position on canvas. Negative moves left, positive moves right. Pixels not on canvas are cropped. |
flipX | Flips applied image in the x direction |
flipY | Flips applied image in the Y direction |
rotateDeg | Angle to draw the image at |
pal | Palette data to use to transform the image |