Luiz Luiz - 10 months ago 27
Swift Question

Score based on time Swift

I'm totally new to Swift (started working on this yesterday) so I don't know where to start.

Basically I'm making a game where the score shall increment every 0.25 seconds (after the game started -

). I was thinking in something with
, but I didn't know what to do.

And I also have to place it in the top center of screen (landscape). I tried using
but it didn't work.


I did it!! I mean, I found some code, videos and texts that helped to do it =)

//Score scoreLabel.position = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2) self.addChild(scoreLabel)

//Score incrementing by time let delay = SKAction.waitForDuration(0.25) let incrementScore = SKAction.runBlock ({ self.score = self.score + 1 self.scoreLabel.text = "\(self.score)" }) self.runAction(SKAction.repeatActionForever(SKAction.sequence([delay,incrementScore])))

I didn't used NSTimer because I read that it couldn't be paused/resume (what I will need to do later).

Thank you =)