How do I fade music towards the end of a layout?

Get help using Construct 2

Post » Fri Jul 11, 2014 5:34 pm

A friend and I are making a side-scrolling/platforming RPG. We've been spending a lot of time writing original music for each unique area of the game, so implementation of the music is pretty important to us.

I think it would be really cool if the music played at a consistent volume throughout a layout, but gradually faded out as the player reached the end of said layout. It would be even better if the player then started on the next layout in silence, and the new music for that layout gradually faded in as they walk forwards.

Sorry if that's a bit confusing or needs some additional clarification.

Has anyone done anything like this? Or have any ideas as to how we could implement this? Thank you so much in advance!!! :D
B
4
Posts: 17
Reputation: 228

Post » Fri Jul 11, 2014 6:14 pm

volume = distance from player to end of layout / distance between player and end of layout to start fading.

You can use an invisible object to control this distance and use it's width when calculating
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Fri Jul 11, 2014 6:42 pm

@caiorosisca That's interesting! I've been toying with invisible objects to do this a little bit. I'm pretty new to Construct, so I'm not entirely sure I grasp everything you're saying. How would you suggest using the object's width in the calculation? Thank you! :)
B
4
Posts: 17
Reputation: 228

Post » Fri Jul 11, 2014 7:10 pm

volume = abs(Player.X - LayoutWidth) / greenBox.width

Grey is layout size(pretend it on my img).
Blue is at the position where it ends, represented by LayoutWidth.

using this formula when the player is at the left side of the greenbox (this is the region the player needs to be inside for the volume to fade) volume will be 1, and when at the right side volume will be 0.

Note, volume will be 0 exactly at the end of the greenbox, where the blue line is. if the player moves further to the right volume will start going up again. so it's important that it is at the end of layout.
Image
http://imgur.com/jtUyw76
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Fri Jul 11, 2014 7:39 pm

@caiorosisca Ok awesome! That works exactly how you described! The only problem for me now is, I'm using the XAudio2 object, which has max volume set as 0, and the minimum set as -100. So instead of fading from 1 to 0, I need to fade from 0 to -100. I know I'm an idiot for asking, but I'm not very great at math... Haha! How would you adjust the formula to do that?
B
4
Posts: 17
Reputation: 228

Post » Fri Jul 11, 2014 7:58 pm

I'm not good at maths either, but I think that is the formula your are after. Give it a try, if it doesn't work search for the equation of the line

vol = (greenBox.width*100 + -100 * abs(Player.X - LayoutWidth))/-greenBox.width
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Fri Jul 11, 2014 8:24 pm

@caiorosisca No way, it worked!!!! With a couple extra parenthesis. You're far better at math than I am!!!! Thank you so much!
B
4
Posts: 17
Reputation: 228

Post » Sun Jul 13, 2014 6:14 am

@caiorosisca Sorry to be bothersome, but I have one more question about this. I'm trying to make it so the "green box" doesn't need to be placed exactly at the end of the layout. I've been trying to fix the equation so the distance between the right edge of the "green box" and an object placed at the right edge of the layout is subtracted from the equation. I've been working on this for quite a while, but I'm falling up short somehow. If you could help me with this I would be soooooooooooooooo thankful!
B
4
Posts: 17
Reputation: 228


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 22 guests