Waiting for SpriteKit animations to finish

When the idea for a new game struck, I decided to give Apple’s SpriteKit a try. Having done some Cocos2D projects in the past, I found SpriteKit easy to jump into and pretty pleasant to work with. There are some unfortunate oddities like the update function returning the total time that has passed so far instead of the delta. Easy to get around, but still annoying. So implementing the game logic went swimmingly, but getting animations to work properly put me into a bit of a pickle. When certain animations were going if the screen was tapped the game logic would advance but the animations would not be done yet. This generally worked except sometimes the resulting screen would be showing the wrong sprites or the animations would start acting strangely. For certain animations I needed to temporarily disable input. But there are other ongoing animations that I do not want to pause input.

So this is what I came up with.

-(BOOL)touchablesAreAnimating{
  BOOL retVal = NO;

  for (SKSpriteNode* s in touchablesArray) {
    if ([s hasActions]) {
      retVal = YES;
    }
  }
  return retVal;
}

touchablesArray holds all of the SKSpriteNodes that can be interacted with, so I just check if they are animating (hasActions) and return YES if any of them do.

Now I just place a check in the start of my touch routine and we are good to go. This makes it impossible to pause during animations, which may or may not be a good thing. Considering that at most I could have a second or two of time where the game cannot be paused I do not think it will be an issue, but something I will have to play with.

What this also allows is for me to stop the game’s timer during these animations. So the animations play out and show the player what they have accomplished and it does not count against their remaining playtime.

Could I be any more vague about what kind of game I am making? Hmm.