Debacle
Debacle

Reputation: 1221

call func when action completes?

First off, thanks for your time. I have a fairly simple problem to solve but can't seem to figure it out.

I'm making a Tower Defense game, I'd like to have it when the enemies reach their destination the life bar shrinks. I figure it must be as easy as adding another action to the sequence that calls a method that can reduce the life points but I haven't found a way. Any help would be greatly beneficial.

        let enemy1 = SKSpriteNode(imageNamed: "magSquare.png")
        enemy1.position = startPoint

        let step1 : SKAction = SKAction.moveTo(firstTurn, duration: duration)
        let step2 : SKAction = SKAction.moveTo(secondTurn, duration: duration)
        let step3 : SKAction = SKAction.moveTo(thirdTurn, duration: duration)
        let step4 : SKAction = SKAction.moveTo(fourthTurn, duration: duration)
        let step5 : SKAction = SKAction.moveTo(fifthTurn, duration: duration)
        let step6 : SKAction = SKAction.removeFromParent()
        //let step7 : SKAction = SKAction.** call method **

        enemy1.runAction(SKAction.sequence([step1, step2, step3, step4, step5, step6]))

        self.addChild(enemy1)

Upvotes: 1

Views: 70

Answers (1)

hamobi
hamobi

Reputation: 8130

let step7 = SKAction.runBlock({ self.yourfunc() })

Upvotes: 2

Related Questions