Can't get 3D sound effect for skAudioNode in SpriteKit
I am testing a new skAudioNode that was announced at WWDC 2015. I am new to swift and spriteKit.
First, in the sks editor, I drag and drop an Audio object into the scene and name it audioNodeRed, which is attached to the visually red sprikit node. I am pointing the wav file link to this node in the editor.
In GameScene.swift I wrote:
let redNode:SKAudioNode = childNodeWithName("//audioNodeRed") as! SKAudioNode;
let actionPlaySound = SKAction.play()
redNode.runAction(actionPlaySound)
The last line will fail with an error: application terminated due to uncaught exception "com.apple.coreaudio.avfaudio", reason: "prerequisite is false: _engine-> IsRunning ()"
I fixed it by pointing the wav file to a code action (xcode error?)
let actionPlaySound =SKAction.playSoundFileNamed("Crackling_Fireplace.wav", waitForCompletion: false)
Now I can hear the sound, but there is no 3D sound, if I move the node I already specified the position of the scene listener (still in GameScene.swift):
//sprite is a skSpriteNode in the center of the screen
self.listener = sprite
Another thing is that I cannot access the avaudioengine properties specified in the Apple documentation . eg.
redAudioNode.avAudioNode //SKAudioNode does not have a member named "avAudioNode"
myScene.audioEngine //SKScene does not have a member named "audioEngine"
I am using XCode 7 beta4. I want to know if I am doing something wrong here, or the reason is that the ios9 framework is still in beta testing. Thanks for the help.
------------- add ----------------
OK, I got a 3D effect by going to the background and going back to the app again.
source to share