prime31/SpriteKit — pull request #2 by PolCPP (2013-04-21 19:24:19+00:00)
Title: Minor delay issue when switching from an animation to another

I've found that switching from an animation (for example idling) to another (walking) had a small delay that.

Since its better to see it than explaining it here's a pair of demos and the source of the first one (without the bug fixed)

[slow-transition](http://dl.dropboxusercontent.com/u/69084784/Spritekit/spritekit_issue_a/spritekit_issue_a.html)
[instant-transition](
https://dl.dropboxusercontent.com/u/69084784/Spritekit/spritekit_issue_b/spritekit_issue_b.html)

[slow-transition-source](https://dl.dropboxusercontent.com/u/69084784/Spritekit/demo-project.zip) so you can see what's going on.

If you quickly tap on the first one you'll see that the animation remains the same when it should switch for at least a frame to the running ones. On the second one it acts the way i think it should.

The problem is basically this

if( desiredFrame != _currentFrame )
{
_currentFrame = desiredFrame;
_sprite.setUVs( animationState.textureInfo[_currentFrame].uvRect );
}

Since on the first moment both frames are 0 you wont get inside, so until desired frame turns 1 you're stuck on your old animation. It's pretty noticeable on slow framerates with things like walking since you can be ~100 ms with the old animation.

To fix it in a resource friendly way i just defaulted _currentFrame (and reset it when the animation stops) to -1.