1
votes

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)
1
What is the purpose of declaring variables step<n>? Why not just: enemy1.runAction(SKAction.sequence([SKAction.moveTo(...), SKAction.moveTo(...), SKAction.moveTo(...), ...]). Use a <newline> after each 'step' and the code is easily more concise and readable. - GoZoner

1 Answers

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