A game without sound is dull, so let’s add some music!

Music is set up in the ORK Framework editor and can be used by Music Players and the Event System.

Setting up music

First we’ll create some music clips, open the ORK Framework editor and navigate to World > Music. We will need 4 music clips in our game, one is already added by default, so add 3 music clips and change the following settings.

Music clip 0

  • Name
    Change to Town Theme.
  • Audio Clip
    Select Town Theme (can be found in Assets/Tutorial Resources/Music/).
  • Loop Clip
    Enable this setting.
    We want the town theme to loop when it’s finished playing.

Music clip 1

  • Name
    Change to Field Theme.
  • Audio Clip
    Select Field Theme (can be found in Assets/Tutorial Resources/Music/).
  • Loop Clip
    Enable this setting.

Music clip 2

  • Name
    Change to Battle Theme.
  • Audio Clip
    Select Battle Theme (can be found in Assets/Tutorial Resources/Music/).
  • Loop Clip
    Enable this setting.

Click on Add Loop to add an in-clip loop – they are used to loop specific parts of an audio clip. Loops are performed in order, if you add more than one loop, you can variate the looping part.

  • Check Time (s)
    Set to 146.
    The clip will play until 2:26.
  • Set Time (s)
    Set to 58.
    The clip should continue on 0:58.

Music clip 3

  • Name
    Change to Victory Theme.
  • Audio Clip
    Select Victory Theme (can be found in Assets/Tutorial Resources/Music/).
  • Loop Clip
    Disable this setting.

Ok, we’re done with the music settings – click on Save Settings.

Music in the scenes

Now we’ll add music to our scenes using the Music Player component.

gametutorial_6_let_there_be_music1

The music player is a simple scene event that can change the music. You can stop the current music clip, play a new one or fade between clips.

Main menu scene

Open the main menu scene (0 Main Menu) and add a music player using the ORK Scene Wizard: Create Object > Music Player. We want no music to be played in the main menu scene, so we’ll set the music player to stop the music in this scene. Change the following settings.

  • Start Type
    Set to Autostart (this should be the default setting).
  • Play Type
    Set to Stop.

This will stop the music when the scene is loaded. Save the scene.

Town scene

Open the town scene (1 Town) and add a music player. Change the following settings in the inspector.

  • Start Type
    Set to Autostart (this should be the default setting).
  • Play Type
    Set to Fade To.
    We want to fade from the currently playing music to a new clip when the scene is loaded.
    If the new clip has already been playing, nothing will happen (no fading).
  • Music
    Select Town Theme.
  • Interpolation
    Select Linear.
  • Fade Time (s)
    Set to 1.
    The music will be faded in 1 second from the old clip to the new one.

Save the scene.

Field scene

Open the fieldscene (2 Field) and add a music player. Change the following settings in the inspector.

  • Start Type
    Set to Autostart (this should be the default setting).
  • Play Type
    Set to Fade To.
  • Music
    Select Field Theme.
  • Interpolation
    Select Linear.
  • Fade Time (s)
    Set to 1.

Save the scene.

That’s all we need to do, so change to the main menu scene (0 Main Menu) and hit play. You’ll hear the music when starting a new game and the music will fade between different clips when changing scenes.

And that’s it for now – the next lesson will cover area names.