|
Gama C Library
Gama C API Documentation
|
Defines structures and functions for managing 2D sprites and animations. More...
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 |
| Defines the maximum number of frames an animation sequence can have. | |
Functions | |
| gmSpriteAnim | gm_sprite_anim_browse (int n_sprites, double interval) |
| Creates a sprite animation that sequentially browses through all available 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. | |
Defines structures and functions for managing 2D sprites and animations.
This file provides utilities for creating animated sprites from sprite sheets, controlling their animation, and drawing them to the screen.
| #define GAMA_MAX_SPRITE_ANIM_LENGTH 10 |
Defines the maximum number of frames an animation sequence can have.
| gmSpriteAnim gm_sprite_anim_browse | ( | int | n_sprites, |
| double | interval ) |
Creates a sprite animation that sequentially browses through all available frames.
This function creates a simple animation where each frame of the sprite sheet is played in sequential order from 0 to n_sprites - 1.
| n_sprites | The total number of frames in the sprite sheet. |
| interval | The time interval in seconds between each frame. |
| gmSpriteAnim gm_sprite_anim_create | ( | double | interval, |
| const char * | pattern ) |
Creates a sprite animation based on a pattern string.
Each character in the pattern string corresponds to a frame index, where 'a' maps to frame 0, 'b' to frame 1, and so on. This allows for custom animation sequences.
| interval | The time interval in seconds between frames. |
| pattern | A string where each character represents a frame index (e.g., "abcba" for a looping animation). |
Creates a new sprite from an image with a specified number of frames.
This function initializes a sprite from a gmImage that is assumed to be a sprite sheet. The n_frames parameter specifies how many equal-width frames are contained horizontally within the image.
| img | The gmImage containing the sprite sheet. |
| n_frames | The number of animation frames horizontally arranged in the sprite sheet. |
| 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.
This function automatically calculates the correct slice of the sprite sheet to draw based on the current animation frame.
| sprite | Pointer to the sprite to draw. |
| x | The x-coordinate of the center of the sprite. |
| y | The y-coordinate of the center of the sprite. |
| width | The width to draw the sprite. |
| height | The height to draw the sprite. |
| void gm_sprite_update_dt | ( | gmSprite * | sprite, |
| double | dt ) |
Updates the sprite's animation state based on elapsed time.
| sprite | Pointer to the sprite to update. |
| dt | Delta time since the last update. |