gpt4 book ai didi

xcode - swift 和 spritekit 中的倒计时

转载 作者:行者123 更新时间:2023-11-28 10:26:22 29 4
gpt4 key购买 nike

我正在尝试对我的应用程序进行倒计时。我正在使用 SKLabelNode。这是我的代码:

class PlayScene: SKScene {
var startCount = true
var setTime = 0
var myTime = 0
var printTime = SKLabelNode(fontNamed: "arial")
override func didMoveToView(view: SKView!) {
self.backgroundColor = UIColor(hex: 0xD64541)
self.printTime.text = NSString(format: "%i", self.myTime)
self.addChild(self.printTime)
}
override func update(currentTime: NSTimeInterval) {
if self.startCount == true {
self.setTime = Int(currentTime)
self.startCount = false
}
self.myTime = Int(currentTime) - self.setTime
}
}

我编译它没有问题,但它在执行时崩溃了......我认为这是我对字符串的转换......

谢谢

最佳答案

希望对您有所帮助。你几乎拥有它

class PlayScene: SKScene {

var startCount = true
var setTime = 0
var myTime = 0
var printTime = SKLabelNode(fontNamed: "arial")

override func didMoveToView(view: SKView) {
self.backgroundColor = UIColor.orangeColor()

//self.printTime.text = NSString(format: "%i", self.myTime)//you need the position
self.printTime.position = CGPointMake(self.size.width * 0.5, self.size.height * 0.5)
self.addChild(self.printTime)
}
override func update(currentTime: NSTimeInterval) {
if self.startCount == true {
self.setTime = Int(currentTime)
self.startCount = false
}
self.myTime = Int(currentTime) - self.setTime
self.printTime.text = ("format:\(self.myTime)")//put your label in update so it shows each second.
}

关于xcode - swift 和 spritekit 中的倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24865420/

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