如何使用倒数计时器来停止游戏 – iOS [SWIFT] –

如何使用倒数计时器来停止游戏 – iOS [SWIFT] –,第1张

概述我的游戏应该在60年代后停止.但我的计时器代码没有任何反应. var timer = NSTimer()var counter:Int = 60var labelCounter:SKLabelNode = SKLabelNode() 这是我的GameScene类中的代码: func startTimer(){ timer = NSTimer.scheduledTimerWithTim 我的游戏应该在60年代后停止.但我的计时器代码没有任何反应.

var timer = NSTimer()var counter:Int = 60var labelCounter:SKLabelNode = SKLabelNode()

这是我的GameScene类中的代码:

func startTimer(){    timer = NSTimer.scheduledTimerWithTimeInterval(1.0,target: self,selector: Selector("updateTimer:"),userInfo: nil,repeats: true)}func updateTimer(dt:NSTimer){    counter--    if counter == 0 {        timer.invalIDate()        removeCountDownTimerVIEw()    } else{        labelCounter.text = "\(counter)"    }}func removeCountDownTimerVIEw(){    scene.vIEw.paused = true}

感谢您的见解 :-)

解决方法 试试这样的事……

overrIDe func vIEwDIDLoad() {    super.vIEwDIDLoad()    //calling the wait function     self.callForWait()}func callForWait(){    //setting the delay time 60secs.    let delay = 60 * Double(NSEC_PER_SEC)    let time = dispatch_time(disPATCH_TIME_Now,Int64(delay))    dispatch_after(time,dispatch_get_main_queue()) {         //call the method which have the steps after delay.        self.stepsAfterDelay()    }}func stepsAfterDelay(){   //your code after delay takes place here...}
总结

以上是内存溢出为你收集整理的如何使用倒数计时器来停止游戏 – iOS [SWIFT] –全部内容,希望文章能够帮你解决如何使用倒数计时器来停止游戏 – iOS [SWIFT] –所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1080973.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存