NSTimer won't start (Swift)

96 views Asked by At

I'm trying to programatically make a timer that counts in seconds and is able to stop when the game ends.

at the top I have this variables defined

var timeCount = 0
var timerRunning = true
var timer = NSTimer()

and then this function under it

func counting() {

    timeCount++
    scoreLabelNode = SKLabelNode(fontNamed:"[z] Arista Light")
    scoreLabelNode.text = String(timeCount)
    scoreLabelNode.zPosition = 100
    scoreLabelNode.fontSize = 500
    scoreLabelNode.alpha = 0.03
    scoreLabelNode.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/4)
    self.addChild(scoreLabelNode)

}

I also added this to start the timer in didMoveToView

if timerRunning == false {

        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("counting"), userInfo: nil, repeats: true)
        timerRunning = true
    }

    counting()
0

There are 0 answers