-
Notifications
You must be signed in to change notification settings - Fork 3
darnit_sprite.h
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 *d_sprite_new(DARNIT_TILESHEET *tilesheet);
- DARNIT_SPRITE *d_sprite_load(const char *fname, int dir, DARNIT_PFORMAT target_format);
- DARNIT_SPRITE *d_sprite_free(DARNIT_SPRITE *sprite);
- void d_sprite_direction_set(DARNIT_SPRITE *sprite, int dir);
- void d_sprite_activate(DARNIT_SPRITE *sprite, int dir);
- void d_sprite_frame_set(DARNIT_SPRITE *sprite, int frame);
- void d_sprite_move(DARNIT_SPRITE *sprite, int x, int y);
- void d_sprite_rotate(DARNIT_SPRITE *sprite, int angle);
- void d_sprite_animate_start(DARNIT_SPRITE *sprite);
- void d_sprite_animate_pause(DARNIT_SPRITE *sprite);
- void d_sprite_animate_stop(DARNIT_SPRITE *sprite);
- void d_sprite_animate_repeat(DARNIT_SPRITE *sprite, DARNIT_SPRITE_ANIMATION repeat);
- void d_sprite_draw(DARNIT_SPRITE *sprite);
- void d_sprite_frame_entry(DARNIT_SPRITE *sprite, int dir, int frame, int tile, int time);
- int d_sprite_width(DARNIT_SPRITE *sprite);
- int d_sprite_height(DARNIT_SPRITE *sprite);
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;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
- tilesheet - A DARNIT_TILESHEET to use for the tiles in the sprite
Return value
Returns NULL on failure, everything else is a valid DARNIT_SPRITE.
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.
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.
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.
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.
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.
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.
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.
void d_sprite_animate_start(DARNIT_SPRITE *sprite);
Starts animation for sprite.
Arguments
- sprite - The sprite to start animating
Return value None.
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.
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.
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.
void d_sprite_draw(DARNIT_SPRITE *sprite);
Draws a sprite and handles animation.
Arguments
- sprite - The sprite to draw
Return value None.
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.
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.
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.