gpt4 book ai didi

ios - applicationWillResignActive == 崩溃

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

游戏、Sprite Kit、来电问题等:

class GameScene: SKScene {
var pauseBool = true
...............
func pauseGame(){
self.scene?.view?.isPaused = true
}

func playGame(){
self.scene?.view?.isPaused = false
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

for touch: AnyObject in touches {
let location = touch.location(in: self)
if pauseButton.contains(location) {
if pauseBool {
pauseGame()
pauseBool = false
} else {
playGame()
pauseBool = true
}
}
}
.............
extension GameScene {
func applicationDidBecomeActive() {
playGame()
}

func applicationWillResignActive() {
pauseGame()
}

如果按下暂停按钮=一切正常!总是!如果来电、短信或 HomeButton = 50/50 崩溃!谢谢!

最佳答案

找到解决办法了!就我而言,在游戏中播放声音时存在冲突。

相反:

run(SKAction.playSoundFileNamed("Wow", waitForCompletion: false))

使用:

func allShortSound(name: String) {
if let shortSound = childNode(withName:
"shortSound") {
shortSound.removeFromParent()
}
let shortSnd = SKAudioNode(fileNamed: name)
shortSnd.name = "shortSound"
shortSnd.autoplayLooped = false
addChild(shortSnd)
shortSnd.run(SKAction.play())
}

然后在正确的地方我们调用这个函数

allShortSound(name: "Wow")

现在一切都很完美!

塔!

关于ios - applicationWillResignActive == 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51244733/

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