Growler

Music overlays

Recommended Posts

I'm creating an adventure game that will have a couple different play packs / versions / worlds using MelonJS 5.1.

Each pack will have the same baseline overworld music loop, but I'd like to layer on other tracks at the same time. The idea being to add a bit of flare distinction to separate play packs while saving costs on reproducing the same baseline track with subtle differences.

The MelonJS Audio API seems basic: https://melonjs.github.io/melonJS/docs/me.audio.html

Is it possible to be a bit technical with overlaying tracks/fade in/fade out?

---------

If not possible through MelonJS engine, do you have other recommendations via Chrome API / web browser APIs to achieve this?

Share this post


Link to post
Share on other sites

Actually even though the API looks simple, you can do a lot with it.

 

first of all, every time you call the play method, it will create a new instance of the given audio asset if required (e..g. already playing), and the method does return  a unique instance ID. Once you have that instance id, you will notice that all other methods are taking an optional instance id parameters, so that you can either apply the "method" to the whole group of just a specific instance id.

 

Not sure if I am clear, but basically it allows you to do something like that :

// start "inGameMusic"
var id1 = me.audio.play("inGameMusic"); // will return 1 as an example

// start a second instance of "inGameMusic"
var id2 = me.audio.play("inGameMusic"); // will return 2 assuming that this second call was made before "inGameMusic" ended up playing (as a result of the first call).

// see the second instance of "inGameMusic"
me.audio.seek("inGameMusic", 1000, id2);

// speed down and fade first instance
me.audio.rate("inGameMusic", 0.5, id1);
me.audio.fade("inGameMusic", 0, 1.0, 1000, id1);

 

and of course you can do the same with different audio assets, and play any track you want on top of any other.

if you do mix different track, then the instance ID is not required, as this is only for different instances of the same audio assets

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.