OneFour
OneFour

Reputation: 45

Beginning and End of animation using SKAction.animateWithTextures in Swift

I'm working on a little project in spritekit and can't quite figure something out. I am animating a sprite using SKAction.animateWithTextures and moving through and array. Works fine just like it should. The issue is that I would like to a function that starts when the animation starts and one when it ends. I see there is a .animationDidStart(CAAnimation), but because what I'm doing is not a CAAnimation I can't really use it. Is there something like this for the method I'm using? As you can may or may not be able to tell I'm still rather new to swift. Thanks for any help in advance.

Upvotes: 2

Views: 537

Answers (1)

Craig Siemens
Craig Siemens

Reputation: 13276

I'd create a sequence of actions. First a block action to call your method you want called when the animation starts, then your animateWithTextures action, finally another block action that calls your finished method.

let startAction = SKAction.runBlock {
    self.startAnimation()
}

let textureAction = SKAction.animateWithTextures...

let finishedAction = SKAction.runBlock {
    self.finishedAnimation()
}

SKAction.sequence([startAction, textureAction , finishedAction])

Upvotes: 3

Related Questions