Mercurial > molko
changeset 127:6691c9f69028
core: animation_update now returns true when complete
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 06 Oct 2020 13:52:52 +0200 |
parents | 52148edddcc6 |
children | 365e40e92800 |
files | libcore/core/animation.c libcore/core/animation.h |
diffstat | 2 files changed, 13 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/libcore/core/animation.c Tue Oct 06 13:52:18 2020 +0200 +++ b/libcore/core/animation.c Tue Oct 06 13:52:52 2020 +0200 @@ -54,7 +54,7 @@ an->elapsed = 0; } -void +bool animation_update(struct animation *an, unsigned int ticks) { assert(an); @@ -62,7 +62,7 @@ an->elapsed += ticks; if (an->elapsed < an->delay) - return; + return false; /* Increment column first */ if (++an->column >= an->sprite->ncols) { @@ -75,6 +75,10 @@ else an->column = 0; } + + return an->elapsed >= an->delay && + an->row >= an->sprite->nrows && + an->column >= an->sprite->ncols; } void
--- a/libcore/core/animation.h Tue Oct 06 13:52:18 2020 +0200 +++ b/libcore/core/animation.h Tue Oct 06 13:52:52 2020 +0200 @@ -33,11 +33,11 @@ * \brief Animation object */ struct animation { - struct sprite *sprite; /*!< Sprite to use (RW) */ - unsigned int row; /*!< current row (RO) */ - unsigned int column; /*!< current column (RO) */ - unsigned int delay; /*!< delay between frames (RW) */ - unsigned int elapsed; /*!< elapsed time since last frame (RO) */ + struct sprite *sprite; /*!< (RW, ref) Sprite to use. */ + unsigned int row; /*!< (RO) Current row. */ + unsigned int column; /*!< (RO) Current column. */ + unsigned int delay; /*!< (RO) Delay between frames. */ + unsigned int elapsed; /*!< (RO) Elapsed time since last frame. */ }; /** @@ -73,8 +73,9 @@ * \pre an != NULL * \param an the animation * \param ticks the elapsed ticks since the last call + * \return true if the animation is complete */ -void +bool animation_update(struct animation *an, unsigned int ticks); /**