SKAction.playSoundFileNamed not working in iOS 9

2019-05-23 22:59发布

问题:

I think I've got my game working almost the same as it was before iOS 9 came along...

I have included the entire function, but the only thing I am having a problem with is the sound effect at the beginning of the function:

func collisionHappened() {
       let bangSoundEffect = SKAction.playSoundFileNamed("Bang.mp3", waitForCompletion: false)
        runAction(bangSoundEffect) //nothing happens here

    let defaults = NSUserDefaults()
    let highscore = defaults.integerForKey("highscore")
    if (score > highscore){
        defaults.setInteger(score, forKey: "highscore") }
    var showHighScore = defaults.integerForKey("highscore")
    let userDefaults = NSUserDefaults.standardUserDefaults()
    var totalScore = userDefaults.integerForKey("totalScoreKey")
    totalScore += self.score
    userDefaults.setInteger(totalScore, forKey: "totalScoreKey")
    var current = defaults.integerForKey("currentscore")
    defaults.setInteger(score, forKey: "currentscore")
    var showcurrentscore = defaults.integerForKey("currentscore")
     backgroundMusicPlayer.stop()
 let explosion = SKEmitterNode(fileNamed: "rocketExplosion") { 
    explosion.position = rocket.position
    explosion.zPosition = 100
    addChild(explosion) }

    rocket.removeFromParent() 
    let sceneChange = gameOverScene(size: self.size) //change scene
    sceneChange.scaleMode = scaleMode
    let reveal = SKTransition.crossFadeWithDuration(1.5)
    self.view?.presentScene(sceneChange, transition: reveal)
    reveal.pausesOutgoingScene = false }

Working fine for iOS 8, but nothing happens in iOS 9. What's changed?? There is no error, its just that nothing happens anymore. If it makes a difference, the sound effect is about half a second long.

UPDATE: I tried adding a println() (which is now print lol) to this function to make sure it's there's no problems with my collisions and its being called. It is, and the rest of the function work fine so the problem only lies with the SKAction :(

回答1:

I find the answer...maybe help you

self.runAction(SKAction.playSoundFileNamed(“Achievement.caf”, waitForCompletion: false))