计时器在swift Spritekit中出现问题

时间:2016-01-18 17:59:28

标签: ios swift timer

我在SpriteKit中创建了一个计时器并将其放在touchesBegan函数中,但是当我第二次触摸屏幕时计时器的结果加倍时,我需要写一个限制,可以使用多少次触摸来启动计时器。一些帮助将不胜感激

 override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   for touch: AnyObject in touches {


          var actionrun = SKAction.runBlock({
        self.score++
        self.timesecond++
        if self.timesecond == 60 {self.timesecond = 0}
        self.ScoreLabel.text = "\(self.score/60):0\(self.timesecond)"


          })



    ScoreLabel.runAction(SKAction.repeatActionForever(SKAction.sequence([actionwait,actionrun])))

1 个答案:

答案 0 :(得分:0)

这里是为任何需要它的人提供的完整解决方案。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   for touch: AnyObject in touches {




    if ScoreLabel.text == "0:00"{

    let actionrun = SKAction.runBlock({
       self.score++
        self.timesecond++
        if self.timesecond == 60 {self.timesecond = 0}
        self.ScoreLabel.text = "\(self.score/60):0\(self.timesecond)"


          })

   ScoreLabel.runAction(SKAction.repeatActionForever(SKAction.sequence([actionwait,actionrun])))

    }