Jump to content

Music overlays


Growler
 Share

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?

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...