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] –所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)