Jump to content


Photo

Stopping a Looping Sound


  • Please log in to reply
8 replies to this topic

#1 MashMashMash

MashMashMash

    GMC Member

  • New Member
  • 42 posts
  • Version:Unknown

Posted 04 April 2012 - 11:16 PM

CREATE EVENT:
sound = sound_loop(snd_fuse);

DESTROY EVENT:
sound_stop(sound);

I want a sound to play on an instance_creation and loop, but the particular instance of that sound to stop once the object is destroyed. It's for a bomb, so each bomb has its own fuse sound playing. I don't want one bomb to explode and all the fuse sounds to stop from other bombs.

This code does not work for my desired effect. The sound starts and loops, but does not stop when the instance is destroyed. Any insight? Thanks!
  • 0

#2 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 04 April 2012 - 11:56 PM

Sorry, I'm not sure what you're problem is. But if it is that when one sound is stopped, all the sounds are stopped, this is how you fix it:

CREATE EVENT:
sound = sound_add("youre_sound",0,1);
sound_loop(sound);
youre_sound is the file name of the fuse audio.

DESTROY EVENT:
sound_stop(sound);

  • 0

#3 MashMashMash

MashMashMash

    GMC Member

  • New Member
  • 42 posts
  • Version:Unknown

Posted 05 April 2012 - 03:09 AM

THe problem is that the sound doesn't stop AT ALL. Does sound_play return the sound that was played? Does it return anything at all? I'd rather not add a new resource to the game because of how many bombs there can be used...
  • 0

#4 TechnoGeek4681

TechnoGeek4681

    GMC Member

  • New Member
  • 143 posts
  • Version:GM8

Posted 05 April 2012 - 03:31 AM

If you use sound_loop(snd_fuse), use sound_stop(snd_fuse) as well. All of the sound play/stop functions take the sound index, which is the resource name. If sound_loop even returns anything, it's likely not helpful to you in any way.
  • 0

#5 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 05 April 2012 - 03:47 AM

sound_loop() doesn't appear to return anything useful. Stopping the sound by sound_stop() will stop ALL your snd_fuses.

Could you edit the sound file to make it go for the desired time so you can just use sound_play() and not have to stop it?
Or you could place the sound on a continuous loop using the alarm event.

Edited by M.D.Simmo, 05 April 2012 - 03:50 AM.

  • 0

#6 MashMashMash

MashMashMash

    GMC Member

  • New Member
  • 42 posts
  • Version:Unknown

Posted 05 April 2012 - 05:12 AM

Well the problem is that there may be several instances of the bomb, so a separate sound loop for each bomb's fuse needs to play, then stop when the bomb is blown up.
  • 0

#7 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 05 April 2012 - 05:41 AM

create event
alarm[0] = 30; //change 30 to the length of the sound
sound_play(snd_fuse);
alarm[0]
alarm[0] = 30;
sound_play(snd_fuse);
This will make each instance play it's own sound until it is destroyed.
  • 0

#8 MashMashMash

MashMashMash

    GMC Member

  • New Member
  • 42 posts
  • Version:Unknown

Posted 05 April 2012 - 07:19 AM

Well let's say the sound to be looped is half a second long. If the instance is destroyed almost immediately after the sound starts, the sound will still play for half a second after the instance is gone.

Is there a way to fix that? sound_stop (or is it stop_sound?) will stop all the instances playing that sound, won't it?
  • 0

#9 M.D.Simmo

M.D.Simmo

    -- ·- - -

  • GMC Member
  • 204 posts
  • Version:GM8.1

Posted 05 April 2012 - 07:46 AM

What you could do, is have another object playing the sound.
On the step event of the new object, have something similar to:
if (instance_number(obj_bomb) >= 1) {
    if (!sound_isplaying(snd_fuse)) {
        sound_play(snd_fuse);
    }
} else {
    sound_stop(snd_fuse)
}
This will mean that only one sound file will ever be playing. As soon as all bombs are destroyed, the sound will stop.

Edited by M.D.Simmo, 05 April 2012 - 07:47 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users