A node that plays audio.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
SKAudio object is used to add an audio to a scene. The sounds are played automatically using AVFoundation, and the node can optionally add 3D spatial audio effects to the audio when it is played.
The currently presented
SKScene object mixes the audio from nodes in the scene based on parameters defined in the
AVAudio3DMixing protocol. A scene’s
audio property allows overall control of volume and playback.
SKAudio objects are positional, i.e. their
positional property is set to
YES. If you add an audio node to a scene with a
listener set, SpriteKit will set the stereo balance and the volume based on the relative positions of the two nodes.
You can explicitly set the volume or stereo balance to an audio node by running actions on it.
SpriteKit includes actions that reduce an audio node’s volume by changing either its occlusion or obstruction. The difference between these actions is that occlusion affects both the direct and reverb paths of the sound while obstruction only affects the direct path. The change volume action offers absolute control over an audio node’s volume.
You can manually set the stereo balance of an audio node with a stereo pan action.
Special effects, such as speeding up or slowing down audio by changing the playback rate and adding reverb are also available as audio actions.
To learn more about audio actions, see Conrolling the Audio of a Node.