Fade in and fade out music

For questions about using Classic.

Post » Sat May 03, 2014 3:28 pm

Hello

Does anyone know how to make a fade in and fade out effect using the XAudio2

Thanks
B
7
S
2
G
1
Posts: 16
Reputation: 596

Post » Sat May 03, 2014 5:37 pm

Do you mean like positional sounds? (they get louder and quieter as you get closer to them), or pure volume fade?

If so, then the best way is to use a global variable for volume (eg: "MusVol"), maybe a second global variable for whether to fade in/out or not at all (eg: "MusFade", 0 for no fade, -1 for out, 1 for in), then a variable for how much to fade by per second (eg: "FadeSpeed").

Code would look something like this:

IF MusFade = -1 & MusVol > 0 THEN MusVol = MusVol - (FadeSpeed * timedelta)

IF MusFade = 0 THEN MusVol = 100% (I forget exactly if it's in a value between 0-1, or 0-100, or even in dB where 0 is loudest)

IF MusFade = 1 & MusVol < 100% THEN MusVol = MusVol + (FadeSpeed * timedelta)

That's in pseudocode (not real code of any language), so things like "MusFade" would have to be written in Construct's way like: global.value('MusFade')
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests