Continuous music play and fade in/out

Game Editor comments and discussion.

Continuous music play and fade in/out

Postby relaxis » Sun Sep 17, 2006 3:18 pm

Is there any way to get the music to fade out when a button is pressed?

Also, is there any way to get the music to KEEP on playing from the first dat file when the LoadGame(); function is used to load another dat file?

(ie - music play event on file 1, load file 2 - keep playing music from file1)
User avatar
relaxis
 
Posts: 82
Joined: Mon Jul 17, 2006 2:06 pm
Location: Luxembourg
Score: 1 Give a positive score

Postby makslane » Mon Sep 18, 2006 12:06 pm

To fade the music, just change the music volume with the variable musicvol (0.0 - 1.0) in a Draw Actor or Timer event.

After load the second game file, the music will stops. So, you need to play again.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby d-soldier » Sun Apr 08, 2007 7:04 pm

If I already have a sound file playing (ie. buring sound near animated fire) and I want to set up an active bounding box (canvas/filled region) where the sound will play, and as the player(actor)walks out of that region, the sound fades out.. how would i do that? And please be specific, I'm dumb when it comes to coding. :shock:
User avatar
d-soldier
 
Posts: 703
Joined: Sun Apr 08, 2007 2:13 am
Score: 61 Give a positive score

Postby makslane » Sun Apr 08, 2007 7:23 pm

d-soldier wrote:If I already have a sound file playing (ie. buring sound near animated fire) and I want to set up an active bounding box (canvas/filled region) where the sound will play, and as the player(actor)walks out of that region, the sound fades out.. how would i do that? And please be specific, I'm dumb when it comes to coding. :shock:


You need to store the channel used to play the sound.
The channel can be a integer variable (actor).

To track when start the fade, use other variable (like canFade) and set to true when the player walk out of the region.

Is better create a variable volume (real, actor) and initialize with the value 1.0 to make the fade.

In the Draw Actor event, put something like:

Code: Select all
if(canFade && volume > 0.0)
{
  //Fade
  setVolume(channel, volume);
  volume *= .99;
}




Look more here:
http://game-editor.com/forum/viewtopic. ... ht=channel
http://game-editor.com/docs/script_refe ... #setvolume

About variable creation:
http://game-editor.com/forum/viewtopic.php?t=3246
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

How to control the speed of the volume fade?

Postby DST » Wed Apr 18, 2007 7:08 am

The fade works, but it takes a long time to reach zero. Is there a way to speed it up? Whenever I lower either volume(variable) or the fade (.99) it only makes the sound drop to that level before fading out, and then fades at the slow speed. Any Ideas?
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Postby makslane » Wed Apr 18, 2007 3:38 pm

Try some low value like .5

Code: Select all
volume *= .5;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Music Fade is uncontrollable

Postby DST » Tue May 08, 2007 6:12 am

As i said in my previous post, when you lower that value, the music immediately switches to that value upon fade, and then fades out at the same speed. going from 100 to 50 in a split second, then taking 15 seconds to reach zero...well, that's a horrible fade. The fade length seems to be uncontrollable. I want to go from 99 to 0 in a matter of 3 seconds. Please tell me how to do this.
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Postby Fuzzy » Tue May 08, 2007 7:37 pm

Make an array.

in global code do this:

float Fade[16] = {0.9375, 0.875, 0.8125, 0.75, 0.6875, 0.625, 0.5625, 0.5, 0.4375, 0.375, 0.3125, 0.25, 0.1875, 0.25, 0.125, 0.0625};

Initialize an integer to zero and use that to refer to the Fade[16]. with each draw, add 1 to the int.

if (count < 16)
{
setVolume(channel, Fade[count]);
count ++;
}

You can do some nifty tricks with this. Take the distance of the player from the sound actor. change the distance from a float to an int with a type cast...

SoundDist = (int)distance(player.x, player.y, enemy.x, enemy.y);

and then force it to a positive value....

SoundDist = abs(SoundDist);

so now its 0 to whatever. we need to change it to the same range as the number of elements in the array. Its called normalizing. We do it with an AND operator.

SoundDist = SoundDist & 16;

So now GE considers out distance to be from 0 to 16. We use this to look up Fade...

setVolume(channel, Fade[SoundDist]);

A third way.... No array required.... use an int called SoundDist, same as before, and a float var called Vol.

switch(SoundDist)
{
case 0 :
Vol = 1.0;
break;
case 1 :
Vol = 0.9;
break;
case 2 :
Vol = 0.8;
break;
}

and so on...

A fourth way. This is the smoothest result. Determine the max distance you want to hear the sound at. Store it in a float var. Lets use MaxDist for a name. use a float called Vol to store our final result.

Get the distance from the player to the enemy.

Dist = distance(player.x, player.y, enemy.x, enemy.y);

which gives a nice float value from 0.0 to whatever. Add a tiny amount to it because we are going to divide, and want to avoid divide by zero errors.

Dist = Dist + 0.001;

Now we divide the two variables.

Vol = MaxDist / Dist;

But wait! at full distance, we get a vol of 1.0! thats no good! we need to reverse it.. easily done.

Vol = 1.0 - Vol;

and we set the volume as before..

setVolume(channel, Vol);


Done! Not checked for errors though!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron