Gama C Library
Gama C API Documentation
Loading...
Searching...
No Matches
sprite.h File Reference
#include "image.h"
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  gmSpriteAnim
 Structure representing a sprite animation sequence. More...
struct  gmSprite
 Structure representing a sprite with animation capabilities. More...

Macros

#define GAMA_MAX_SPRITE_ANIM_LENGTH   10

Functions

gmSpriteAnim gm_sprite_anim_browse (int n_sprites, double interval)
 Creates a sprite animation that sequentially browses through frames.
gmSpriteAnim gm_sprite_anim_create (double interval, const char *pattern)
 Creates a sprite animation based on a pattern string.
gmSprite gm_sprite_create (gmImage img, int n_frames)
 Creates a new sprite from an image with a specified number of frames.
void gm_sprite_update_dt (gmSprite *sprite, double dt)
 Updates the sprite's animation state based on elapsed time.
void gm_sprite_draw (gmSprite *sprite, double x, double y, double width, double height)
 Draws the current frame of a sprite at the specified position and size.
gmSprite gm_sprite_open (const char *path, int n_frames)
 Creates a new sprite by loading an image from a file.

Macro Definition Documentation

◆ GAMA_MAX_SPRITE_ANIM_LENGTH

#define GAMA_MAX_SPRITE_ANIM_LENGTH   10

Function Documentation

◆ gm_sprite_anim_browse()

gmSpriteAnim gm_sprite_anim_browse ( int n_sprites,
double interval )

Creates a sprite animation that sequentially browses through frames.

Parameters
n_spritesThe number of sprites/frames in the animation.
intervalThe time interval between frames.
Returns
A new gmSpriteAnim instance.

◆ gm_sprite_anim_create()

gmSpriteAnim gm_sprite_anim_create ( double interval,
const char * pattern )

Creates a sprite animation based on a pattern string.

Parameters
intervalThe time interval between frames.
patternA string where each character represents a frame index (a=0, b=1, etc.).
Returns
A new gmSpriteAnim instance.

◆ gm_sprite_create()

gmSprite gm_sprite_create ( gmImage img,
int n_frames )

Creates a new sprite from an image with a specified number of frames.

Parameters
imgThe image containing the sprite sheet.
n_framesThe number of frames in the sprite sheet.
Returns
A new gmSprite instance.

◆ gm_sprite_draw()

void gm_sprite_draw ( gmSprite * sprite,
double x,
double y,
double width,
double height )

Draws the current frame of a sprite at the specified position and size.

Parameters
spritePointer to the sprite to draw.
xThe x-coordinate to draw at.
yThe y-coordinate to draw at.
widthThe width to draw the sprite.
heightThe height to draw the sprite.

◆ gm_sprite_open()

gmSprite gm_sprite_open ( const char * path,
int n_frames )

Creates a new sprite by loading an image from a file.

Parameters
pathThe file path to the sprite sheet image.
n_framesThe number of frames in the sprite sheet.
Returns
A new gmSprite instance.

◆ gm_sprite_update_dt()

void gm_sprite_update_dt ( gmSprite * sprite,
double dt )

Updates the sprite's animation state based on elapsed time.

Parameters
spritePointer to the sprite to update.
dtDelta time since the last update.