mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-03-04 09:11:27 +01:00
character: support non-repeating animations (stopping at the last frame)
This commit is contained in:
parent
4240b47380
commit
c3adf398b1
2 changed files with 20 additions and 10 deletions
|
@ -182,7 +182,7 @@ SYMBOL_EXPORT void RegisterSpritesheet(struct Game* game, struct Character* char
|
|||
s->width = 0;
|
||||
s->height = 0;
|
||||
|
||||
s->repeats = strtolnull(al_get_config_value(config, "animation", "repeats"), 0);
|
||||
s->repeats = strtolnull(al_get_config_value(config, "animation", "repeats"), -1);
|
||||
|
||||
s->successor = NULL;
|
||||
const char* successor = al_get_config_value(config, "animation", "successor");
|
||||
|
@ -278,7 +278,7 @@ SYMBOL_EXPORT struct Character* CreateCharacter(struct Game* game, char* name) {
|
|||
character->flipX = false;
|
||||
character->flipY = false;
|
||||
character->shared = false;
|
||||
character->repeats = 0;
|
||||
character->repeats = -1;
|
||||
character->reversing = false;
|
||||
character->parent = NULL;
|
||||
character->hidden = false;
|
||||
|
@ -369,12 +369,8 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
}
|
||||
}
|
||||
|
||||
if (character->spritesheet->frameCount == 1) {
|
||||
character->pos = 0;
|
||||
}
|
||||
|
||||
if (reachedEnd) {
|
||||
if (character->repeats) {
|
||||
if (character->repeats > 0) {
|
||||
character->repeats--;
|
||||
if (character->callback) {
|
||||
character->callback(game, character, NULL, character->spritesheet->name, character->callbackData);
|
||||
|
@ -386,16 +382,30 @@ SYMBOL_EXPORT void AnimateCharacter(struct Game* game, struct Character* charact
|
|||
if (character->callback) {
|
||||
character->callback(game, character, character->spritesheet->name, old, character->callbackData);
|
||||
}
|
||||
}
|
||||
if ((character->reversed) && (character->predecessor)) {
|
||||
} else if ((character->reversed) && (character->predecessor)) {
|
||||
char* old = character->spritesheet->name;
|
||||
SelectSpritesheet(game, character, character->predecessor);
|
||||
if (character->callback) {
|
||||
character->callback(game, character, character->spritesheet->name, old, character->callbackData);
|
||||
}
|
||||
} else {
|
||||
if (character->repeats == 0) {
|
||||
if (character->reversed) {
|
||||
character->pos = 1;
|
||||
} else {
|
||||
character->pos = character->spritesheet->frameCount - 1;
|
||||
}
|
||||
if (character->callback) {
|
||||
character->callback(game, character, NULL, character->spritesheet->name, character->callbackData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (character->spritesheet->frameCount == 1) {
|
||||
character->pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
character->frame = &character->spritesheet->frames[character->pos];
|
||||
|
|
|
@ -89,7 +89,7 @@ struct Character {
|
|||
int confineY; /*!< Height of the canvas being drawn to, for correct position calculation; when -1, uses parent's confines or viewport size */
|
||||
bool flipX; /*!< Flips the character's sprite vertically. */
|
||||
bool flipY; /*!< Flips the character's sprite horizontally. */
|
||||
int repeats; /*!< Number of repeats left before the spritesheet is changed to its successor. */
|
||||
int repeats; /*!< Number of repeats left before the spritesheet is changed to its successor or stopped. */
|
||||
bool reversing; /*!< Whether the animation is currently played backwards. */
|
||||
bool reversed; /*!< Whether the current animation has been requested as reversed. */
|
||||
bool hidden;
|
||||
|
|
Loading…
Add table
Reference in a new issue