Sound and Music

From Game Editor

Jump to: navigation, search

Game editor allows you to play music and play sounds. The formats are:

  • Sounds are wav format
  • Music is ogg format

To play a sound, use the function PlaySound2. To play music, use PlayMusic2.

These will give you the option to choose the file, the volume, the panning, the # of times to loop, and (with music) the status priority.

You can assign them to a channel using a global integer. For instance, go to the variables tab and create a variable in names 'sfx'. Then, to call a sound function in a script editor:

 sfx=PlaySound2("data/ahit4.wav", 1.000000, 1, 0.000000);

The arguments are: (filename, volume, loop, pan).

You can then control the sound using sfx. For instance:

 stopSound(sfx); //will kill the sound playing in channel sfx.
 stopSound(0); //will kill all sounds!

The same thing applies to music;

 music=PlayMusic2("data/mysong.ogg", 1.000000, 10, 0.000000);
 StopSound(music); //will kill the sound.

In addition, you can set the volume of the music on the fly:


Additional Notes:

You can use panning to create a 3d sound environment, i.e.

 float pdist=abs(float)(enemy.x-view.width/2)/(float)(view.width/2);
 //will result in a float of -1 to 1 designating the enemy position.
 sfx=PlaySound2("data/ahit4.wav", 1.000000, 1, pdist);

Using this, sounds will appear to come from the relative direction of the actor specified.

It's best to create sound functions and call them as needed; if you use the specific sound functions all over in various scripts, it will be difficult to control them later on. In addition, you may want to send all explosions and shots to one user defined function, so that there you can limit the number of explosion sounds to play at once (to prevent the volume from overloading).

When calling music from functions, Game Editor may not recognize that the music is being used and may not pack your music in with the game exe. To prevent this, have an actor at startup play all the music by normal triggers, then immediately kill (stopSound(0)); all sounds.