Changing Music during gameplay

3absh3absh Member Posts: 601

At certain conditions I want a different track to play.
I'm trying to make previous music fade out (Audio.Music.volume interpolates to zero) then the new one starts, instead of an instant cutoff of music. This is what I did but it doesn't seem to work

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Put the music before the change attribute or interpolate it back up.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2016

    @abuabed84 said:
    At certain conditions I want a different track to play.
    I'm trying to make previous music fade out (Audio.Music.volume interpolates to zero) then the new one starts, instead of an instant cutoff of music. This is what I did but it doesn't seem to work

    What, specifically, does 'doesn't seem to work' mean in this context ?

  • 3absh3absh Member Posts: 601

    What, specifically, does 'doesn't seem to work' mean in this context ?

    The second part, basically the music fades out but I don't think the part under "timer" is working.

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2016

    @abuabed84 said:

    What, specifically, does 'doesn't seem to work' mean in this context ?

    The second part, basically the music fades out but I don't think the part under "timer" is working.

    I think you are coming in too soon at the end of the interpolate, even if the interpolate takes a single code cycle longer than 1 second to finish (for example 1.0166666666) it will defeat the change-attribute-music-volume-to-1.

    Try chaining the timer from After 1 seconds to something like After 1.02 seconds, if that doesn't work try a slightly longer time.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @Socks said:

    @abuabed84 said:

    What, specifically, does 'doesn't seem to work' mean in this context ?

    The second part, basically the music fades out but I don't think the part under "timer" is working.

    I think you are coming in too soon at the end of the interpolate, even if the interpolate takes a single code cycle longer than 1 second to finish (for example 1.0166666666) it will defeat the change-attribute-music-volume-to-1.

    Try chaining the timer from After 1 seconds to something like After 1.02 seconds, if that doesn't work try a slightly longer time.

    Maybe after the interpolate he should have a stop music behavior and then he knows the other track is stopped. I would also do a quick fade up instead of the change attribute. This will give the second track a moment to fire. I would make the fade up .03 which should be right at the next cycle full volume.

    Interpolate music volume

    Rule

    When game.audio.music.volume = 0

    Stop music

    After 1 second

    Interpolate music volume .03 sec

    Play music

  • 3absh3absh Member Posts: 601

    I think you are coming in too soon at the end of the interpolate, even if the interpolate takes a single code cycle longer than 1 second to finish (for example 1.0166666666) it will defeat the change-attribute-music-volume-to-1.

    Try chaining the timer from After 1 seconds to something like After 1.02 seconds, if that doesn't work try a slightly longer time.

    I changed it to 1.1 and it worked!!!!
    Thanks Socks as always :)

  • 3absh3absh Member Posts: 601

    From now on I really need to rethink timers, I think these sort of solutions require experience more than logic.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @abuabed84 said:
    From now on I really need to rethink timers, I think these sort of solutions require experience more than logic.

    Yes you need to think in terms of the code scan in relation to time

  • SocksSocks London, UK.Member Posts: 12,822

    @Lost_Oasis_Games said:

    @abuabed84 said:
    From now on I really need to rethink timers, I think these sort of solutions require experience more than logic.

    Yes you need to think in terms of the code scan in relation to time

    Agreed, code scan, code cycle, draw cycles, frame rate, call it what you will, it's probably a good thing to have in mind when dealing with these issues.

  • SocksSocks London, UK.Member Posts: 12,822

    @abuabed84 said:
    I changed it to 1.1 and it worked!!!!
    Thanks Socks as always :)

    Good ! :)

Sign In or Register to comment.