Music fade in / out and functions

Get help using Construct 2

Post » Tue Jul 09, 2013 9:07 am

Hi,

I've been trying to create a simple function that lowers the volume of the music in my game, changes it to another music, then increases the volume again, gradually.

Here's what I've come up with:



Unfortunately, nothing plays. I've also tried adding the "stop music" event right before the "wait 1.0 seconds" event, but nothing happens.

I've set a text to show the actual volume of the music, and apparently, it should be playing something... This has been driving me insane! Am I missing something?

Thanks!
B
121
S
41
G
40
Posts: 841
Reputation: 27,857

Post » Tue Jul 09, 2013 9:41 am

Without the capx it's hard to say.
Still, there is something that makes me wander : In the event 2, if the dt is too small (usually the case), the volumeMusic won't ever change from one tick to another because of the round. Why ? Because you substract like 0.2dB, then round it, making it the same again. Just try without the round, you can use floats as volume attenuation.
B
17
S
8
G
4
Posts: 461
Reputation: 6,087

Post » Tue Jul 09, 2013 10:00 am

Thanks for the input! I've atually tried doing that but it didn't change anything.. in any case, since I've got the text object showing the variable VolumeMusic at all times, I could see it was working. It went all the way down to -60, waited for a second, then went all the way up to -10 without a problem.

I'm trying something now that I -think- it might've fixed my problem, but I'm not sure, I'll report back..

Welp, it didn't work.

If I set the function like this:


It works perfectly. But as soon as I try to change the volume, wait, then change it again, the music never plays..andreyin2013-07-09 10:36:53
B
121
S
41
G
40
Posts: 841
Reputation: 27,857

Post » Tue Jul 09, 2013 3:17 pm

Sorry, I didn't clean this up, but I'm guessing you are testing with IE, which has terrible sound support. The trick seems to be that you have to wait after stopping the first Music before starting the second. That's the only way this starts the second Music file. You'll have to clean up the fade with lerp() if you want.

MusicGainTest3.capx
ImageImageImage
B
71
S
20
G
190
Posts: 3,534
Reputation: 108,342

Post » Tue Jul 09, 2013 9:16 pm

Sorry, I should've mentioned the browser! I'm actually using Chrome, though.

I saw your .capx, that is exactly what I wanted. I'm still trying to figure it out though.. but thanks!!
B
121
S
41
G
40
Posts: 841
Reputation: 27,857

Post » Tue Jul 09, 2013 9:42 pm

@blackhornet THANKS SO MUUUCH! I studied your code and understood what was going on, I think.. This whole thing was really confusing to me but you showed me the right direction. Thanks!!

Also I have a question for @ashley - is it possible to have a paramter in the audio object to get which is the music playing, since you can only have 1 music playing at a time anyway? I'm thinking of setting a variable to that but that would mean I would have to set it manually everytime I wanted to change a song..

Thanks again everyone :)
B
121
S
41
G
40
Posts: 841
Reputation: 27,857


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests