April 2021
Beginner to intermediate
506 pages
11h 57m
English
Wouldn’t it be neat to have the background music get louder as the player approaches the exit? (Yeah, I thought so, too.) One of the neat things you can do with SpriteKit and the SKAudioNode class is support 3D spatial audio effects, such as using positional sound based on where a listener node is located.
The listener node is an instance property on an SKScene object. Typically, you’d set the camera or player node to be the scene’s listener. In Val’s Revenge, you’ll set the player node as the listener.
Switch to the GameScene.swift file. Below the setupPlayer() method, add the following code:
| | func setupMusic() { |
| | let musicNode = SKAudioNode(fileNamed: "music") |
| | musicNode.isPositional = false |
Read now
Unlock full access