From 87b203a6ace8d1a82d5464e0897f5edb581915b6 Mon Sep 17 00:00:00 2001 From: Bach Le Date: Wed, 18 Dec 2024 07:10:22 +0800 Subject: [PATCH] Fix looping behaviour for pingpong animation (#254) * Fix looping behaviour for pingpong animation * Fix pingpong animatino for non looping * Simplify bounce back code --- include/cute_sprite.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/include/cute_sprite.h b/include/cute_sprite.h index 78b95a1d..9865e60b 100644 --- a/include/cute_sprite.h +++ b/include/cute_sprite.h @@ -534,20 +534,16 @@ CF_INLINE void cf_sprite_update(CF_Sprite* sprite) if (sprite->frame_index < 0) { if (sprite->loop) { sprite->loop_count++; - sprite->frame_index = frame_count - 1; - } else { sprite->frame_index++; + } else { + sprite->frame_index = 0; } } } else { sprite->frame_index++; if (sprite->frame_index == frame_count) { - if (sprite->loop) { - sprite->loop_count++; - sprite->frame_index = 0; - } else { - sprite->frame_index--; - } + sprite->loop_count++; + sprite->frame_index--; } } }