计时器在快速 Spritekit 中制造问题



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

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

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

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])))
    }

最新更新