[英]Timer making problems in swift Spritekit
我已經在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])))
這是為任何需要它的人提供的完整解決方案。
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.