spacecash21 spacecash21 - 1 year ago 319
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))

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download