Luiz Luiz - 1 year ago 87
Swift Question

Score based on time

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.

Answer Source

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

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

//Score incrementing by time
let delay = SKAction.waitForDuration(0.25)
let incrementScore = SKAction.runBlock ({
    self.score = self.score + 1
    self.scoreLabel.text = "\(self.score)"

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

Thank you =)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download