• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Change sound while playing?

N

NoFontNL

Guest
Is there a way to change the properties of a sound while it is playing?
I have 2 sounds: snLoop; snEnd.

I want to play the snLoop sound in a loop, so
music0 = audio_play_sound(snLoop,1,true);

But when a condition is true, I want to stop the music0 when ended, so set the loop property to false, and when it ends play snEnd.

Is there any way to accomplish above?

Thanks in advance.
 
M

moogthedog

Guest
something like this:

Code:
/// in manager::create
levelEnd=false;
playingSound=noone;
Code:
/// in manager::step
if (playingSound==noone)
{
   playingSound=audio_play_sound(sndLoop,1,false);
}
else
{
   if (audio_sound_get_track_position(playingSound)==0)
   {
       if  (levelEnd)
       {
           audio_play_sound(sndEndLevel);
       }
       else
       {
           playingSound=audio_play_sound(sndLoop,1,false);
       }
   }
}
This uses the step event to loop your sound, and the get_track_position call returns 0 when the sound stops.

Alternatively, loop the sound as you're doing at the moment (still catching the return of the audio_play)sound in an instance variable), and monitor the position in the step event. When the track position jumps backwards (again, store it from step to step in an instance variable), you know it's just cycled round. Then you can stop the sound manually with audio_stop_sound(...) and start playing the level end sound.
 
Top