character: Add SetSpritesheetPosition

This commit is contained in:
Sebastian Krzyszkowiak 2022-07-17 02:28:31 +02:00
parent bf1f58b308
commit 51e0a25734
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 16 additions and 0 deletions

View file

@ -109,6 +109,21 @@ SYMBOL_EXPORT void EnqueueSpritesheet(struct Game* game, struct Character* chara
character->successor = strdup(name);
}
SYMBOL_EXPORT void SetSpritesheetPosition(struct Game* game, struct Character* character, int frame) {
struct Spritesheet* spritesheet = character->spritesheet;
if (!spritesheet) {
return;
}
if (spritesheet->stream) {
PrintConsole(game, "%s: tried to set position of a streaming spritesheet %s!", character->name, spritesheet->name);
return;
}
if (frame < spritesheet->frame_count) {
character->pos = frame;
character->frame = &character->spritesheet->frames[character->pos];
}
}
SYMBOL_EXPORT struct Spritesheet* GetSpritesheet(struct Game* game, struct Character* character, char* name) {
struct Spritesheet* tmp = character->spritesheets;
while (tmp) {

View file

@ -143,6 +143,7 @@ void RegisterSpritesheet(struct Game* game, struct Character* character, char* n
void RegisterStreamedSpritesheet(struct Game* game, struct Character* character, char* name, SpritesheetStream* callback, SpritesheetStreamDestructor* destructor, void* data);
void RegisterSpritesheetFromBitmap(struct Game* game, struct Character* character, char* name, ALLEGRO_BITMAP* bitmap);
struct Spritesheet* GetSpritesheet(struct Game* game, struct Character* character, char* name);
void SetSpritesheetPosition(struct Game* game, struct Character* character, int frame);
ALLEGRO_TRANSFORM GetCharacterTransform(struct Game* game, struct Character* character);
ALLEGRO_COLOR GetCharacterTint(struct Game* game, struct Character* character);