spacecash21 spacecash21 - 4 months ago 59x
Swift Question

SKAction completion handler swift

I'm new to Swift and SpriteKit. A lot of samples for Objective C, but can't get it to work on Swift. Tried looking at other questions, but can't seem to find a good answer for Swift.
So, I'm running an SKAction, but upon SKAction completion, I want it to do something else and I can't seem to get it right in swift.

spaceMan.runAction(spaceManDeathAnimation, completion: {
println("red box has faded out")

Any ideas will be appreciated.


for i in 0...29 {
textures.append(SKTexture(imageNamed: "spaceManDeath_\(i)"))
spaceManDeathAnimation = SKAction.repeatActionForever(SKAction.animateWithTextures(textures, timePerFrame: 0.15625))


You completion code is not called since your "death" action is running forever, which means it will never end.

You can use

+ repeatAction:count:

method for setting a count for how many repeats will be made before finishing:

spaceManDeathAnimation = SKAction.repeatAction(SKAction.animateWithTextures(textures, timePerFrame: 0.15625), count:5)