SKAction.playSoundFileNamed not working in iOS 9

血红的双手。 提交于 2019-12-08 02:55:44

问题


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))


来源:https://stackoverflow.com/questions/32723431/skaction-playsoundfilenamed-not-working-in-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!