Luiz Luiz - 7 months ago 10
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 -

touchesBegan
). I was thinking in something with
waitForDuration(0.25)
, 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
.position
but it didn't work.

Answer

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 =)