Skip to content
Steven Arnow edited this page Jun 1, 2013 · 11 revisions

DARNIT_SPRITE

A DARNIT_SPRITE is an animated sprite with selectable banks "directions". DARNIT_SPRITE is currently also the only drawable in libDarnit that can be rotated.

DARNIT_SPRITE_ANIMATION

Selects if sprite animation repeat is on or off. It is turned on by default.

typedef enum { DARNIT_SPRITE_ANIMATION_NOREPEAT = 0, DARNIT_SPRITE_ANIMATION_REPEAT = 1, } DARNIT_SPRITE_ANIMATION;

d_sprite_new

DARNIT_SPRITE *d_sprite_new(DARNIT_TILESHEET *tilesheet);

Creates a new sprite without any frames. Use d_sprite_frame_entry to populate the sprite.

Arguments

Return value

Returns NULL on failure, everything else is a valid DARNIT_SPRITE.

d_sprite_load

DARNIT_SPRITE *d_sprite_load(const char *fname, int dir, DARNIT_PFORMAT target_format);

Loads a sprite from file. See file formats: sprite for help on how to make sprite files.

Arguments

  • fname - The filename of the sprite to load
  • dir - What sprite index "direction" to initialize it to
  • target_format - If the tilesheet needed by the sprite isn't loaded, load it with this pixel format

Return value

Returns NULL on failure, anything else is a valid DARNIT_SPRITE.

d_sprite_free

DARNIT_SPRITE *d_sprite_free(DARNIT_SPRITE *sprite);

Free's a sprite, and if it also loaded a tilesheet, it tries to unload it as well.

Arguments

  • sprite - The sprite to unload

Return value

Returns NULL for compact pointer clearing.

d_sprite_direction_set

void d_sprite_direction_set(DARNIT_SPRITE *sprite, int dir);

Changes the sprite direction used without resetting the frame counter.

Arguments

  • sprite - The sprite to change direction for
  • dir - The direction to use. Range is 0..31

Return value None.

d_sprite_activate

void d_sprite_activate(DARNIT_SPRITE *sprite, int dir);

Sets the direction of the sprite and enables animation repeat, but does not reset the frame counter or enable animation.

Arguments

  • sprite - The sprite to "activate"
  • dir - The sprite direction to use

Return value None.

d_sprite_frame_set

void d_sprite_frame_set(DARNIT_SPRITE *sprite, int frame);

Set the exact frame of animation to show

Arguments

  • sprite - The sprite to change current frame for
  • frame - The frame number to use. Range is 0..7

Return value None.

d_sprite_move

void d_sprite_move(DARNIT_SPRITE *sprite, int x, int y);

Moves a sprite, setting its upper left corner to x, y.

Arguments

  • sprite - The sprite to move
  • x - The X coordinate to use, in pixels
  • y - The Y coordinate to use, in pixels

Return value None.

d_sprite_rotate

void d_sprite_rotate(DARNIT_SPRITE *sprite, int angle);

Rotates a sprite angle/10 degrees.

Arguments

  • sprite - The sprite to rotate
  • angle - Number of 1/10th of a degree to rotate the sprite (range: 0..3599)

Return value None.

d_sprite_animate_start

void d_sprite_animate_start(DARNIT_SPRITE *sprite);

Starts animation for sprite.

Arguments

  • sprite - The sprite to start animating

Return value None.

d_sprite_animate_pause

void d_sprite_animate_pause(DARNIT_SPRITE *sprite);

Freezes animation for sprite, does not reset frame counter.

Arguments

  • sprite - The sprite to pause animation for.

Return value None.

d_sprite_anumate_stop

void d_sprite_animate_stop(DARNIT_SPRITE *sprite);

Stops animation for sprite and resets the frame counter to frame 0.

Arguments

  • sprite - The sprite to stop animation for

Return value None.

d_sprite_animate_repeat

void d_sprite_animate_repeat(DARNIT_SPRITE *sprite, DARNIT_SPRITE_ANIMATION repeat);

Sets if animation repeats (loops) or not. Default is repeat on.

Arguments

  • sprite - The argument to set animation repeat for
  • repeat - The repeat mode to set

Return value None.

d_sprite_draw

void d_sprite_draw(DARNIT_SPRITE *sprite);

Draws a sprite and handles animation.

Arguments

  • sprite - The sprite to draw

Return value None.

d_sprite_frame_entry

void d_sprite_frame_entry(DARNIT_SPRITE *sprite, int dir, int frame, int tile, int time);

Sets what tile and time to use for sprite sprite at frame frame in direction dir.

Arguments

  • sprite - The sprite to set a frame for
  • dir - The direction to set a frame in, range is 0..31
  • frame - The frame index to modify, range is 0..7
  • tile - The tilesheet tile index to use
  • time - The amount of milliseconds to display the frame

Return value None.

d_sprite_width

int d_sprite_width(DARNIT_SPRITE *sprite);

Returns the tile width for sprite. This number does not change with rotation.

Arguments

  • sprite - The sprite to return tile width for

Return value

The tile width in pixels.

d_sprite_height

int d_sprite_height(DARNIT_SPRITE *sprite);

Returns the tile height for _sprite. This number does not change with rotation.

Arguments

  • sprite - The sprite tp return tile height for

Return value

The tile height in pixels.

Clone this wiki locally