我在 Xcode 中创建了一个游戏,目前主要使用 SpriteKit 中的 update
函数实现。它看起来像这样:
override func update(_ currentTime: TimeInterval) {
if(gameStatus == status.preGame){
//function calls here
}
else if(gameStatus == status.startUp){
//function calls here
}
else if(gameStatus == status.inGame){
//heavy function calls here
}
}
当它在游戏中时,会多次调用以随机创建节点并移动它们等。我遇到了异步线程,并在互联网上进行了搜索,试图弄清楚如何实现它们,但我找不到任何可以帮助我实现我所寻找的东西的东西。
由于我目前的实现方式,我遇到了一些滞后问题,有人告诉我 Async 可能有助于稍微解决这个问题。我想知道是否有人知道如何为我的结构实现它。
感谢您的帮助!
最佳答案
DispatchQueue.global(qos: .background).async {
if(gameStatus == status.preGame){
//function calls here
}
else if(gameStatus == status.startUp){
//function calls here
}
else if(gameStatus == status.inGame){
//heavy function calls here
}
DispatchQueue.main.async {
}
}
关于swift - 实现异步线程(使用 Swift 的 Xcode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45156951/