游戏,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()
}
如果按PauseButton =一切正常!总是! 如果打来的电话或SMS消息或HomeButton = 50/50 CRASH! 谢谢!
答案 0 :(得分:0)
找到解决方案!就我而言,在游戏中播放声音时有冲突。
相反:
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")
现在一切正常!
Ta!