• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Adaptive Audio

D

Donal

Guest
I'm relatively new with GM and I'm trying to implement a very simple adaptive music system. I want an audio track to play and to be able to fade another synchronised track in and out, depending on the player position. I assumed this would be pretty simple but I assumed wrong :p I can't find any tutorials so any pointers in the right direction would be sincerely welcomed!
 
H

Humphrey M

Guest
Its fairly straightforward although I'm not sure if this code will actually work but you would do something like this. Of course replace x and y with the position that you want. Also in the last two lines instead of music1 and music 2 have the current sound and then the sound you want to fade in as the character gets closer to the position.

In the player object you would put:

(create)

music1vol = 100;
music2vol = 0;
distofade = 100;

(step)

if(distance_to_point(x,y) <= distofade){
music1vol = 100 - (100-(distance_to_point(x,y)*(100/distofade + 1)));
music2vol = 0 + (100-(distance_to_point(x,y)*(100/distofade + 1)));
}
audio_sound_gain(music1, music1vol, 0);
audio_sound_gain(music2, music2vol, 0);

Hope this helps
 
Last edited by a moderator:
D

Donal

Guest
Thanks Humphrey! I'm not able to get anything from that - I am able to fade a track out and fade another one in with some other code I've been using but what I want is to fade track 2 in over the track 1. Track 1 is bass and drums, the other is lead - I want the lead track to synchronise with the bass track so that when the player reaches a certain point it will fade in at the right time. There is an add on that does this but apparently it doesn't work with HTML - https://marketplace.yoyogames.com/assets/3238/adaptive-music-player

I'll dig around in this but it will probably be a bit beyond me!
Thanks for your help :)
 
Top