简体   繁体   English

快速Spritekit中的计时器制作问题

[英]Timer making problems in swift Spritekit

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. 我已经在SpriteKit中创建了一个计时器并将其放在touchesBegan函数中,但是当我第二次触摸屏幕时,计时器的结果翻倍,因此我需要限制可以使用多少触摸来启动计时器。 Some help would be much appreciated 一些帮助将不胜感激

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

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

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM