Skip to content

Adding music

Peter Crew edited this page Dec 28, 2018 · 1 revision

Today, we'll be looking at another simple modding topic - music. The music in-game can be played using the music player, and can be added to a custom playlist.


Once again, I'll be starting off with a blank template for my mod:

// register the mod directly
ModRegistry.registerMod(new Mod({
   // the smart name of the mod
   name : "Equilinox Variations",
   // the version to be displayed
   version : "1.0.0",
   // the author(s) of the mod
   author : "pcr3w",
   // a brief overview of the mod's purpose
   description : "An extremely simple mod to add new music to the game.",
   
   // run when the mod is initiated
   init : function() {
      // the rest of the code in this tutorial will be added to here
   }
}));

The next part is to place the actual audio files in the correct place (the assets/sound/ sub-directory within the mod folder). Equilinox supports the .wav and .ogg sound formats.

The music can now actually be added into the game by registering it with the SoundRegistry in init.

// we can load the sound file from the `sound` directory in our assets folder
var aria = SoundRegistry.load("Goldberg Variations - Aria.wav");

// the new music track can then be registered with the game
SoundRegistry.registerMusic({
   // we need a unique ID to reference this specific track
   id : 988,
   // this name will be shown to the players when they select their music
   name : "J.S. Bach, Goldberg Variations - Aria",
   // the actual Sound object is provided to the registry here
   music : aria,
   // this is optional, stating that the track will not be locked
   locked : false
});

Loading up the game will show that the modding has been successful, and we now have the Aria of Bach's Goldberg Variations in Equilinox!


You now know how to customise the game with new tasks and music, but to add more substance to your mods, you can add new entities.

The next part of these tutorials will be a lot longer, as we'll be covering creating your own entities. This is more involved due to the large number of things that entities can have.

Clone this wiki locally