gpt4 book ai didi

ios - 计时器在 swift Spritekit 中产生问题

转载 作者:行者123 更新时间:2023-11-30 13:46:27 24 4
gpt4 key购买 nike

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

}

关于ios - 计时器在 swift Spritekit 中产生问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com