计时器在swift Spritekit中出现问题

时间:2022-12-03 07:26:23

I have created a timer in SpriteKit and put it in the touchesBegan function, but when I touch the screen a second time the result of the timer doubles, I need to write a limit to how many touches can be used to start the timer. Some help would be much appreciated

我在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 个解决方案

#1


0  

Here's the completed solution for anyone who needs it.

这是完成的解决方案,适合任何需要它的人。

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

    }

#1


0  

Here's the completed solution for anyone who needs it.

这是完成的解决方案,适合任何需要它的人。

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

    }