Skip to content
Steven Arnow edited this page Nov 30, 2013 · 10 revisions

DARNIT_MTSPRITE

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.

d_mtsprite_new

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.

d_mtsprite_load

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

d_mtsprite_free

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

Return value

A NULL-pointer for compact pointer clearing.

d_mtsprite_animate_start

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

Return value None.

d_mtsprite_animate_pause

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

Return value Ńone

d_mtsprite_animate_stop

void d_mtsprite_animate_stop(DARNIT_MTSPRITE *mtsprite);

Stops animation of the given DARNIT_MTSPRITE and resets frame counter to the first frame.

Arguments

Return value None.

d_mtsprite_animate_repeat

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.

d_mtsprite_tile_add

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.

d_mtsprite_frame_set

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.

d_mtsprite_draw

void d_mtsprite_draw(DARNIT_MTSPRITE *mtsprite);

Draws a DARNIT_MTSPRITE and animates it if animation is enabled.

Arguments

Return value None.

d_mtsprite_time_left

int d_mtsprite_time_left(DARNIT_MTSPRITE *mtsprite);

Returns the number of milliseconds left for before the current frame is changed. On non-looping sprites, this value will always be zero when the frame time is up, but it will never be zero for looping sprites.

Arguments

Return value

The number of milliseconds left for the current frame of animation.

Clone this wiki locally