Reputation: 168
I am trying out the new skAudioNode which is announced in WWDC 2015. I am new to swift and spriteKit.
First in sks editor I drag an Audio object into scene and give a name as audioNodeRed which attached to a visually red sprikit node. I specify a 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 crash with an error : terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: _engine->IsRunning()'
I fixed it by specified a wav file to action by code (xcode bug?)
let actionPlaySound =SKAction.playSoundFileNamed("Crackling_Fireplace.wav", waitForCompletion: false)
Ok now I can hear the sound but there's no 3d audio effect if I move the node, I have already specify the listener position of the scene(still in GameScene.swift):
//sprite is a skSpriteNode in the center of the screen
self.listener = sprite
Another thing is I can not access the avaudioengine properties as specified in the Apple documentation. e.g.
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 beta version4. I want to know if I am doing something wrong here or the reason is the ios9 framework is still in beta. Thanks for the help.
-------------add----------------
OK, I got the 3d audio effect by going to the background and going back to the app again.
Upvotes: 3
Views: 845
Reputation: 168
OK, I figure out the problem myself, apparently there is something wrong with the sks editor.
if I do it in code in stead of in the editor, I hear the 3D sound effect.
audioNodeRed.positional = true
audioNodeRed.autoplayLooped = true
Upvotes: 2