我自己也遇到过这个问题。仅供参考,我的解决方案很快,所以如果您仍在使用它,请将其转换为Objective C。
对我来说,我的解决方案包括两个部分。首先,我必须在场景文件的didMoveToView函数中初始化我的SoundAction SKAction。所以,你的场景文件应该是这个样子:
import SpriteKit
import GameKit
import AVFoundation
class GameScene: SKScene, SKPhysicsContactDelegate {
var sSharedShootSoundAction: SKAction = SKAction()
override func didMoveToView(view: SKView) {
/* Setup your scene here */
sSharedShootSoundAction = SKAction.playSoundFileNamed("plane_shoot.aiff", waitForCompletion: false)
}
}
然后在您的AppDelegate文件,你需要将下面的代码行中的应用程序didFinishLaunchingWithOptions功能。 (请勿忘记导入您的APPDELEGATE AVFOUNDATION)。所以你的应用代理方法应该像这样:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// INSERT THIS LINE BELOW.
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient, error: nil)
return true
}
希望这能为你解决它,就像它为我做的那样!让我知道如果它不。
是否预装了该音频文件? – prototypical
不,这不是... –
尝试预加载它... :) – prototypical