Music fade in / out and functions

0 favourites
  • 6 posts
From the Asset Store
6 looping tracks to use in your games and projects. These tracks are in the style of the 1960s detective movie genre.
  • 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:

    <img src="http://i.imgur.com/tJPzk3T.png" border="0" />

    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!

  • 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.

  • 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:

    <img src="http://i.imgur.com/Sm0AuzG.png" border="0" />

    It works perfectly. But as soon as I try to change the volume, wait, then change it again, the music never plays..

  • 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

  • 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!!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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 :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)