We’d love to hear from you. Whether you have a question that you’d like us to answer as part of our FAQ,  you’ve identified something that just doesn’t quite look right in one of our tutorials, you have a business opportunity or for any other reason, please use this simple form to contact us.

We’ll do our best to provide a prompt response.

Sound and Music

There are a couple of ways you can use sound in the Armory game engine and we will look at all of them now. First let’s start by playing a simple sound effect, in this case a .WAV file. You can also use .OGG and .MP4 platforms, depending on the platform you are targeting. WAV is an ideal format for playing sound effects, while OGG is better for longer audio files, such as music or dialogs. First, we need to get a resource into our game. In the Armory properties, click Project Folder.

Armory3D Armory Project

This will open your local file system browser, such as Windows Explorer on Windows or Finder on Mac. Create a new folder called “Bundled” in this directory

Next drop your .WAV file into this folder. If you need a source for .WAV files, try FreeSound.org if you wish to download some, or https://bfxr.net/ or http://sfbgames.com/chiptone/ if you wish to make your own simple sound effects.

Let’s start with a Haxe example, create a node in the scene or use the default cube and attached the following trait/script to it:

package arm;

class SoundPlayer extends iron.Trait {
  public function new() {
    super();
    notifyOnUpdate(function() {
      if(iron.system.Input.getKeyboard().down("s")){
        iron.data.Data.getSound("belch.wav",function(sound:kha.Sound){
          iron.system.Audio.play(sound);
        });
      }
    });
  }
}

The code is pretty straight forward, in the update callback of our trait, we check to see if the ‘S’ key is pressed, if it is we call getSound(), which takes two parameters. The first is the name of the sound file to load, the second is the callback function to call when the loading is done. Once the file is loaded we play it will a call to Audio.play() passing our newly loaded audio file.

Now let’s perform the exact same task using nodes instead. Before we continue however, we are going to have to make the sound effect available in Armory. First start by hitting Space Bar and typing open sound:

sound Armory3D

A file choosing dialog will now appear, select the sound file you just added to the Bundled folder. Next in the Outliner, switch to Data-Blocks mode:

data blocks mode Armory3D

Now scroll down and Sounds, expand it and select your newly added sound, click the text box to the right of Fake User.

Armory3D sounds

Open the Node Editor, switch to game mode and create the following Node tree called “SoundPlayer”:

Armory3D Soundplayer

Now make sure that you create a trait, of type Nodes and attach your newly created node:

Armory3D Armory Traits

The final way you can play sound in Armory is using the Speaker object in Blender. Select Add->Speaker in 3D View.

Speaker Object Armory3D

Now select the Speaker Icon in the Properties panel, drop down the Music note dialog and select the wav file.

Armory3D Speaker Icon

Now create the following node tree:

Armory3D node tree

In the Play Speaker node, be sure to select the newly created Speaker in Blender. The nice thing about using the Speaker node is you have details control over the way the audio is played such as the volume:

Armory3D Play Speaker Node

Handling Input<<PreviousTable of ContentsNext>>Creating Custom Nodes

script ends --->