Search code examples
iosswiftskaction

How to use runAction syntax correctly for the following


I'm trying to do the following

//increase spaceship frequency
    self.runAction(SKAction.repeatActionForever(SKAction.waitForDuration(1), completion: {

        difficulty -= 0.01
        println("difficulty increased")

    }))

Basically I need the SKAction.waitForDuration(1) with the completion to run forever so I tried to wrap it around with another runAction

I get the following error: "Extra argument 'completion' in call"


Solution

  • If you really want to use SpriteKit, use a action sequence:

    self.runAction(SKAction.repeatActionForever(SKAction.sequence([SKAction.waitForDuration(1), SKAction.runBlock({
        difficulty -= 0.01;
        println("difficulty increased");
    })])));
    

    But, you really should be using NSTimer.