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:
Sebastian Krzyszkowiak 2019-11-18 09:47:13 +01:00
parent 08a3c24c56
commit 332c668717
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF
2 changed files with 7 additions and 0 deletions

View file

@ -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);
}

View file

@ -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;