我有一个简单的游戏,其中一个球跳过障碍物。当它与障碍物接触时(无论是在跳跃时还是在跳跃之前碰撞时),我想在转换到主菜单屏幕(GameScene.Swift)之前播放声音。肯定会检测到didBeginContact但不一定是didEndContact 由于某种原因,声音文件无法播放。我做错了什么?
PlayScene.Swift文件
class PlayScene: SKScene, SKPhysicsContactDelegate{
//......
let losingSoundAction = SKAction.playSoundFileNamed("losing.wav", waitForCompletion: true)
//....
func didBeginContact(contact: SKPhysicsContact) {
//play the losing sound
self.runAction(losingSoundAction)
contact.bodyA.categoryBitMask = ColliderType.Hero.rawValue
died()
}
func died(){
//change back to main screen
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
let skView = self.view as SKView!
scene.scaleMode = .AspectFill
scene.GameSceneInstance = self
scene.score = score
skView.presentScene(scene)
}
}
}
答案 0 :(得分:0)
我将dead()函数调用移到了didEndContact(),这似乎解决了这个问题。