|
|
@@ -6,8 +6,24 @@ using namespace WalrusRPG;
|
|
|
|
|
|
namespace
|
|
|
{
|
|
|
+ unsigned get_animation_duration(const WalrusRPG::Animation &anim) {
|
|
|
+ unsigned duration = 0;
|
|
|
+ for (unsigned index = 0; index < anim.stripe.size(); index++) {
|
|
|
+ duration += anim.stripe[index].duration;
|
|
|
+ }
|
|
|
+ return duration;
|
|
|
+ }
|
|
|
+
|
|
|
unsigned find_frame(const WalrusRPG::Animation &anim, signed frame_time)
|
|
|
{
|
|
|
+ unsigned duration = get_animation_duration(anim);
|
|
|
+ if (frame_time >= duration && !anim.looping) {
|
|
|
+ // simple looping checking
|
|
|
+ // Also, a flag to detect if the animation ended could be an option
|
|
|
+ return anim.stripe[anim.stripe.size() - 1].frame;
|
|
|
+ }
|
|
|
+ frame_time %= duration;
|
|
|
+
|
|
|
unsigned index = 0;
|
|
|
do
|
|
|
{
|