LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
|
=== Sprites structs and funcs ===
LG_Sprite are only graphical objects at the moment - next thing to do is adding some kind of "behaviour" and making frames usage less tedious.
Another option is to create a new struct ("character" or whatnot) whose first member is a sprite.
LG_Sprite lg_sprite | ( | const char * | file_name[], |
LG_Color_u | lg_color_u_key, | ||
int | w, | ||
int | h | ||
) |
Create a new sprite (LG_Sprite)
=== ALL IMAGES MUST BE SQUARE (ie width = height) ===
All images are scaled to w, h (or first image dims if -1, -1)
Scaling may degrade image quality, so original dims should be prefered
From the SDL2 doc: "The color key defines a pixel value that will be treated as transparent in a blit"
Then we use a texture atlas
file_name | A NULL terminated array of image file paths |
lg_color_u_key | The color key to use |
w | Sprite width |
h | Sprite height |
int lg_sprite_draw | ( | LG_Sprite * | sprite | ) |
void lg_sprite_free_tex | ( | LG_Sprite * | sprite | ) |
Free sprite's atlas texture
WARNING: freeing the original sprite atlas texture will invalidate all cloned sprites atlas textures, so you should make sure to keep the original sprite around until done with all cloned sprites
sprite | A LG_Sprite instance |
void lg_sprite_set_cur_frame | ( | LG_Sprite * | sprite, |
int | frame | ||
) |
Bla bla (self-explanatory)
int lg_sprite_get_cur_frame | ( | LG_Sprite * | sprite | ) |
Bla bla (self-explanatory)
Create a new sprite which will use the original sprite texture atlas
WARNING: freeing the original sprite atlas texture will invalidate all cloned sprites atlas textures, so you should make sure to keep the original sprite around until done with all cloned sprites
sprite | A LG_Sprite |
Bla bla (self-explanatory)
Bla bla (self-explanatory)
void lg_save_sprite_position | ( | LG_Sprite * | sprite | ) |
Bla bla (self-explanatory)
void lg_restore_sprite_position | ( | LG_Sprite * | sprite | ) |
Bla bla (self-explanatory)
void lg_sprite_info | ( | LG_Sprite * | sprite | ) |
Bla bla (self-explanatory)
void lg_rqdraw_init | ( | Rq_SDraw_Array * | draw_list | ) |
Reset a Rq_SDraw_Array, ie an array of LG_Sprite instances to be drawed in batch
draw_list | A pointer to a Rq_SDraw_Array |
int lg_rqdraw_add_sprite | ( | LG_Sprite * | sprite, |
Rq_SDraw_Array * | draw_list | ||
) |
Add a LG_Sprite instances at the end of a Rq_SDraw_Array, ie an array of LG_Sprite instances to be drawed in batch
Must call lg_rqdraw_init() at start of loop
Array has no duplicates and ends with first NULL element met
draw_list | A pointer to a Rq_SDraw_Array |
sprite | A pointer to a LG_Sprite |