Skip to content
Steven Arnow edited this page Aug 30, 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. NOTE: You must run d_sprite_activate when you're done populating the sprite. If you don't, rendering will be glitchy until the next frame of animation is rendered.

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. It also calculates frame coordinates for the sprite, which is needed when you've just created and populated a new sprite. Not needed when loading a sprite from file, as this function is already called internally.

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_animate_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_set

void d_sprite_frame_entry_set(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_hitbox_set

void d_sprite_hitbox_set(DARNIT_SPRITE *sprite, int dir, int frame, int x, int y, int w, int h);

Sets the hitbox for a frame of the sprite. The default is x,y at 0,0, w,h at tile_w,tile_h.

Arguments

  • sprite - The sprite to modify
  • dir - The direction the frame to set a hitbox for is in
  • frame - The frame to set hitbox for
  • x - The X-coordinate that the hitbox starts on
  • y - The Y-coordinate that the hitbox starts on
  • w - The width of the hitbox
  • h - The height of the hitbox

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 to return tile height for

Return value

The tile height in pixels.

d_sprite_frame

int d_sprite_frame(DARNIT_SPRITE *sprite);

Returns the the current frame for _sprite.

Arguments

  • sprite - The sprite to return frame number for

Return value

The current frame number (0 is the first frame.)

d_sprite_hitbox

void d_sprite_hitbox(DARNIT_SPRITE *sprite, int *x, int *y, int *w, int *h);

Returns the hitbox for the current frame

Arguments

  • sprite - The sprite to return hitbox for
  • x - Number of pixels into the sprite frame that the hitbox start at, X-axis
  • y - Number of pixels into the sprite frame that the hitbox start at, Y-axis
  • w - The width of the hitbox
  • h - The height of the hitbox

Return value None.

d_sprite_hitbox_last

void d_sprite_hitbox_last(DARNIT_SPRITE *sprite, int *x, int *y, int *w, int *h);

Returns the hitbox for the last frame in the sprite.

Arguments

  • sprite - The sprite to return hitbox for
  • x - Number of pixels into the sprite frame that the hitbox start at, X-axis
  • y - Number of pixels into the sprite frame that the hitbox start at, Y-axis
  • w - The width of the hitbox
  • h - The height of the hitbox

Return value None.

Clone this wiki locally