Game Development Reference
In-Depth Information
How to do it…
If we've made the previous recipes, we might already have seen the audio node. The fol-
lowing steps will help show us how to add one to the scene:
1. We can find the audio node by right-clicking on a spatial, in this case the main
scene node, and selecting Add Spatial and then Audio Node .
2. Next, select it and look at the Properties window.
3. The first important thing to look at is the Audio Data parameter. In the drop-down
menu, the SDK will automatically show the files in the Sounds folder under Pro-
ject Assets , so we should see Ocean Waves.ogg here. Unchecking the Positional
checkbox means there will be no falloff in volume as you move around.
4. Also check the Looping box to make sure the sound doesn't end when it's finished
playing one time.
5. It's currently not possible to hear the sound in the SDK itself, so we need to start an
application to do so. Fortunately, only one line of code is needed to start the sound
in our simpleInitApp method. The only catch here is that we need to cast the
scene object in an AudioNode instance first. After having loaded the scene, add
the following lines of code:
Node scene = (Node) assetManager.loadModel
("Scenes/TestScene.j3o");
rootNode.attachChild(scene);
((AudioNode)scene.getChild("AudioNode")).play();
6. The sound we added is a very powerful sound and may be a bit overwhelming for
our scene. Playing with the Volume property of the AudioNode element can be
used to tone down the effect a bit.
Tip
Downloading the example code
You can download the example code files for all Packt topics you have purchased from
your account at http://www.packtpub.com . If you purchased this topic elsewhere, you can
visit http://www.packtpub.com/support and register to have the files e-mailed directly to
you.
Search WWH ::




Custom Search