Time for action – add ambient sound

Let's create an audio node in the simpleInitApp() method, and play it:

  1. Make a copy of Main.java and name the class BackgroundSounds.java. Remember to also refactor the first line of the main() method to BackgroundSounds app = new BackgroundSounds();.
  2. Copy the River.ogg sound file into the assets/Sounds/Environment/ directory.
  3. Use the simpleInitApp() method to load the sound into an audio node:
    public void simpleInitApp() {
    AudioNode natureAudio = new AudioNode(
    assetManager, "Sounds/Environment/River.ogg");
  4. Specify properties of the sound; for example, set the volume to 5. 10 is loudest, 0 is silent.
    natureAudio.setVolume(5);
  5. Switch the sound to play continuously by setting the looping property to true. Note that if ...

Get jMonkeyEngine 3.0 Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.