SKAction.playSoundFileNamed在iOS 9中不起作用 [英] SKAction.playSoundFileNamed not working in iOS 9

查看:80
本文介绍了SKAction.playSoundFileNamed在iOS 9中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的游戏几乎与iOS 9出现之前一样...

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 }

在iOS 8上工作正常,但在iOS 9中没有任何反应.有什么变化?没有错误,只是没有任何反应.如果有所不同,声音效果大约会持续半秒.

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.

更新:我尝试向此函数添加一个println()(现在为print lol),以确保它与我的碰撞及其被调用都没有问题.是的,并且该函数的其余部分都能正常工作,因此问题仅在于SKAction :(

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 :(

推荐答案

我找到了答案……可能对您有帮助

I find the answer...maybe help you

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

这篇关于SKAction.playSoundFileNamed在iOS 9中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆