mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2024-12-12 12:08:00 +01:00
character: don't call character callback indefinitely after animation finishes
This could happen when the repeats counter went down to 0 with no successor - the callback would then be called every frame.
This commit is contained in:
parent
08a3c24c56
commit
332c668717
2 changed files with 7 additions and 0 deletions
|
@ -54,6 +54,7 @@ SYMBOL_EXPORT void SelectSpritesheet(struct Game* game, struct Character* charac
|
|||
character->reversing = tmp->reversed ^ reversed;
|
||||
character->frame = &tmp->frames[character->pos];
|
||||
//character->bitmap = tmp->frames[character->pos].bitmap;
|
||||
character->finished = false;
|
||||
PrintConsole(game, "SUCCESS: Spritesheet for %s activated: %s (%dx%d)", character->name, character->spritesheet->name, character->spritesheet->width, character->spritesheet->height);
|
||||
return;
|
||||
}
|
||||
|
@ -473,6 +474,10 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
return;
|
||||
}
|
||||
|
||||
if (character->finished) {
|
||||
return;
|
||||
}
|
||||
|
||||
delta *= speed_modifier;
|
||||
character->delta += delta * 1000;
|
||||
|
||||
|
@ -535,6 +540,7 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
} else {
|
||||
character->pos = character->spritesheet->frame_count - 1;
|
||||
}
|
||||
character->finished = true;
|
||||
if (character->callback) {
|
||||
character->callback(game, character, NULL, character->spritesheet, character->callback_data);
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ struct Character {
|
|||
bool reversing; /*!< Whether the animation is currently played backwards. */
|
||||
bool reversed; /*!< Whether the current animation has been requested as reversed. */
|
||||
bool hidden;
|
||||
bool finished;
|
||||
void* data; /*!< Additional, custom character data (HP etc.). */
|
||||
CharacterCallback* callback;
|
||||
void* callback_data;
|
||||
|
|
Loading…
Reference in a new issue