jquery.animateSprite
jquery.animateSprite copied to clipboard
Triggering the animateSprite 'play' method in the 'complete' function does not work
Hey - fantastic work on this cool jQuery package.
I'm trying to use it for a neat little project where I'm dynamically switching between some animations. Basically causing a character to pick randomly between a series of animations. It seemed ideal to use the 'complete' function callback to have the animation system automatically switch from one animation to another. Unfortunately, it seems this doesn't work currently.
If I call the animateSprite from within the complete function callback, either directly or via another method the whole animation system stalls. I'm working on a simple workaround using my own timers, but it would be ideal to simply rely on the animation systems own callback functionality.
I'm confused, because I got an e-mail from someone asking to explain my workaround but I don't see their message in this thread?!
In anycase, the workaround is pretty straight forward. Since the animateSprite package allows you to specify a playback rate (i.e. FPS), you can calculate when an animation is scheduled to end and pre-maturely call the JavaScript setTimeout function to trigger a function that then changes the animation upon completion. So if the animation ends in 666ms, you just call setTimeout with the same timing to trigger a new animation after that time.
It is a little bit of a hack, given that it's a timer separate from the integrated animation system, but it works.