-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_mtsprite.h
MT-sprite "Multi-Tile sprite" is a sprite format that allows a variable amount of tiles from a texture per frame. See MTS for more information about the MTS file format used to describe multi-tile sprites. A MT-sprite can only be moved around on the screen via d_render_offset, and it's therefor not recommented to have more than a handful of MT-sprites on screen at once as OpenGL state changes are expensive on some platforms.
- DARNIT_MTSPRITE *d_mtsprite_new(DARNIT_TILESHEET *tilesheet);
- DARNIT_MTSPRITE *d_mtsprite_load(const char *fname);
- DARNIT_MTSPRITE *d_mtsprite_free(DARNIT_MTSPRITE *mtsprite);
- void d_mtsprite_animate_start(DARNIT_MTSPRITE *mtsprite);
- void d_mtsprite_animate_pause(DARNIT_MTSPRITE *mtsprite);
- void d_mtsprite_animate_stop(DARNIT_MTSPRITE *mtsprite);
- void d_mtsprite_animate_repeat(DARNIT_MTSPRITE *mtsprite, int repeat);
- void d_mtsprite_tile_add(DARNIT_MTSPRITE *mtsprite, int x, int y, int w, int h, int rx, int ry);
- void d_mtsprite_frame_set(DARNIT_MTSPRITE *mtsprite, int time);
- void d_mtsprite_draw(DARNIT_MTSPRITE *mtsprite);
DARNIT_MTSPRITE *d_mtsprite_new(DARNIT_TILESHEET *tilesheet);
Creates a new mt-sprite with no frames and no tiles. Uses the texture from the tilesheet provided.
Arguments
- tilesheet - A DARNIT_TILESHEET with the texture to use for the tiles used in animation
Return value
NULL is returned on failure. Anything else is a valid DARNIT_MTSPRITE. The sprite has no frames or tiles defined.
DARNIT_MTSPRITE *d_mtsprite_load(const char *fname);
Loads a MT-sprite from fname, loads and assigns the tilesheet specified in the MTS file. d_mtsprite_load only accepts MTS files.
Arguments
- fname - The file to load as a sprite
Return value
- Returns NULL on failure, anything else is a valid DARNIT_MTSPRITE.
DARNIT_MTSPRITE *d_mtsprite_free(DARNIT_MTSPRITE *mtsprite);
Frees a DARNIT_MTSPRITE and unloads the tilesheet if nothing else is using it. A NULL-pointer is returned for compact pointer clearing.
Arguments
- mtsprite - The DARNIT_MTSPRITE to free
Return value
A NULL-pointer for compact pointer clearing.
void d_mtsprite_animate_start(DARNIT_MTSPRITE *mtsprite);
Starts animation of a MT-sprite. If the animation was paused, it will resume animation from that frame.
Arguments
- mtsprite - The DARNIT_MTSPRITE to start animation of
Return value None.
void d_mtsprite_animate_pause(DARNIT_MTSPRITE *mtsprite);
Pauses the animation for the given DARNIT_MTSPRITE. Frame number and time left on frame is preserved.
Arguments
- mtsprite - The DARNIT_MTSPRITE to pause animation on
Return value Ńone
void d_mtsprite_animate_stop(DARNIT_MTSPRITE *mtsprite);
Stops animation of the given DARNIT_MTSPRITE and resets frame counter to the first frame.
Arguments
- mtsprite - The DARNIT_MTSPRITE to stop animation on
Return value None.
void d_mtsprite_animate_repeat(DARNIT_MTSPRITE *mtsprite, int repeat);
Sets the animation repeat behaviour on the provided sprite. If repeast is turned off, animation will freeze on the last frame. Repeat is turned on by default.
Arguments
mtsprite - The DARNIT_MTSPRITE to set animation repeat mode on repeat - A non-zero value enables animation repeat, zero disables it.
Return value None.
void mtsprite_tile_add(DARNIT_MTSPRITE *mtsprite, int x, int y, int w, int h, int rx, int ry);
Adds a tile to the next frame of animation in the DARNIT_MTSPRITE given by mtsprite.
Arguments
- mtsprite - The DARNIT_MTSPRITE to add a tile to.
- x - The X-coordinate on the tilesheet to start the tile at
- y - The Y-coordinate on the tilesheet to start the tile at
- w - The width of the tile to add
- h - The height of the tile to add
- rx - The relative X-coordinate to actually draw the tile at
- ry - The relative Y-coordinate to actually draw the tile at.
Return value None.
void d_mtsprite_frame_set(DARNIT_MTSPRITE *mtsprite, int time);
Puts all the frames added since the last frame into a new frame following the last one. The frame's duration is time milliseconds.
Arguments
- mtsprite - The DARNIT_MTSPRITE to add a frame to.
- time - Thee frame duration in milliseconds.
Return value None.
void d_mtsprite_draw(DARNIT_MTSPRITE *mtsprite);
Draws a DARNIT_MTSPRITE and animates it if animation is enabled.
Arguments
- mtsprite - The DARNIT_MTSPRITE that should be rendered.
Return value None.