From 332c668717d1dd307af3bf882ce3f5b1ae537ff4 Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Mon, 18 Nov 2019 09:47:13 +0100 Subject: [PATCH] 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. --- src/character.c | 6 ++++++ src/character.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/character.c b/src/character.c index c896f2b..31bb469 100644 --- a/src/character.c +++ b/src/character.c @@ -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); } diff --git a/src/character.h b/src/character.h index 8c7d1e8..8839a95 100644 --- a/src/character.h +++ b/src/character.h @@ -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;