Animation freezes when setting duration is large than was before


When animation is running and you are setting duration greater than was - animation stops for a while.

How to reproduce:

  1. Create animation with several frames (for example, 10 frames with delay per frame - 1 seconds, so total duration = 10 secs)
  2. Run animation on some sprite
  3. Wait until animation has changed several sprite frames (for example, wait 5 seconds, so animation will show frame number 5)
  4. Set new animation duration, which will be greater than previous (for example set duration = 100 seconds)
  5. Now sprite animation will freeze for a while (in our example for about 50 seconds), and then runs normally and change frame every 10 seconds

Why does this happen? Because of that m_elapsed time stored (in CCActionInterval class) in seconds, and after changing duration on 5th frame(after 5 seconds) animation will think that now is only first frame, but stored m_nNextFrame will be set on 6th frame, so we have to wait 10(secs per frame)*6(next frame number) - 5(passed seconds) = 55 seconds for the next frame!

Just add this public method:
inline void setDuration(float duration) { m_elapsed *= duration / m_fDuration; m_fDuration = duration; }
into the CCActionInterval.h.
In the method above on duration changing m_elapsed time is recalculated accordingly to the new duration.

I hope you will decode my English:)
Best regards, Vyacheslav.