How do you get positional audio to work in SceneKit?

坚强是说给别人听的谎言 提交于 2019-12-03 10:22:40

问题


I am having trouble getting positional audio to work in SceneKit. Starting with the SceneKit game template generated by Xcode I have added the following code to the end of the handleTap method:

let ship = scnView.scene!.rootNode.childNode(withName: "ship", recursively: true)!  
if let source = SCNAudioSource(fileNamed: "art.scnassets/monoAudioTest.wav")  
{  
    source.volume = 1  
    source.isPositional = true  
    source.shouldStream = true  
    source.loops = true  
    source.load()  
    let player = SCNAudioPlayer(source: source)  
    ship.addAudioPlayer(player)  
}  

ship.runAction(SCNAction.move(to: SCNVector3(0, 0, -10000), duration: 8)) 

The audio plays but the volume doesn't decrease as the jet moves away from the camera. Am I missing some steps or making some wrong assumptions?

Cross-posted to the Apple Developer Forums.


回答1:


You should be able to get positional audio with source.shouldStream = false.




回答2:


As mentioned by Jed Soane, and confirmed by Apple in a Radar, the issue was my audio file was stereo instead of mono. Only mono audio files will work for positional audio.



来源:https://stackoverflow.com/questions/41555867/how-do-you-get-positional-audio-to-work-in-scenekit

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