StopSound on sound effects

Non-platform specific questions.

StopSound on sound effects

Postby Kodo » Sun Dec 04, 2005 7:41 pm

Is there any way to use stopSound on a sound effect (PlaySound2) without stopping other soud effects and background music. I have an elevator that operates on a switch, when the player is holding down the switch the sound repeats, when they remove the mouse from the button it should stop.

I've tried assigning the elevator sound to a channel...

elevator_sound_2 = PlaySound2("data/Mousetick1.wav", 1.000000, 99, 0.000000);

then on another event I have...

stopSound(elevator_sound_2);

this doesnt do anything.

I've tried playing the samples using PlayMusic2 as well, but when I use stopSound(elevator_sound_2) the background music also stops.


Is there some other way of turning on/off looped sound effects on events that I should be using instead? Is there only one channel that can be turned on/off?

Thanks in advance!
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby makslane » Mon Dec 05, 2005 12:05 pm

Make sure don't change elevator_sound_2 in other place and have sufficient channels in Game Properties.


I've tried playing the samples using PlayMusic2 as well, but when I use stopSound(elevator_sound_2) the background music also stops.


You can play only one music at same time.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Kodo » Mon Dec 05, 2005 7:25 pm

ok the only places there is anything to do with this sound triggering and disabling are on the one 'button' in my game. Theres nothing much else going on except some background music (MOD) and a WAV jump sound effect which doesnt play all the time anyway.

Here's how it was set up, but it doesnt work :(

( elevator_sound is Global, Real )
------------------
EVENT: On Mouse Down
------------------

if (elevator_sound_on == FALSE)
{
PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound_on = TRUE;
}


------------------
EVENT: On Mouse Up
------------------
stopSound(elevator_sound);
elevator_sound_on = FALSE;


This has no effect, when I release the mouse button the sound continues to repeat :( I realise I'm probably doing something stupid, but any help most appreciated!
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby makslane » Mon Dec 05, 2005 7:35 pm

I can't see what is wrong.
If you can, send me the game files (use the subject "StopSound on sound effects" in email)
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Kodo » Mon Dec 05, 2005 8:09 pm

email sent, thanks for your help :)
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score

Postby makslane » Tue Dec 06, 2005 12:46 am

Dr Reed wrote: PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);


Ok, I can see the problem now.

Are you playing two sounds:

A) PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);
B) elevator_sound = PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000);

The stopSound(elevator_sound) are stopping the play B, but can't stop the play A.
You need create other variable to hold the A channel to stop later.
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby Kodo » Tue Dec 06, 2005 10:14 am

Doh!

I just removed PlaySound2("data/Iron.wav", 1.000000, 9999, 0.000000); and now it's working just fine!!

What it was, was that I didn’t realise that Line 'B' would actually start the sample playing, I thought you had to 'A' play the sound and 'B' assign it to a free channel, now I realise What was going on, thanks for the great support, and thanks for the emails :)
User avatar
Kodo
 
Posts: 449
Joined: Thu Oct 20, 2005 8:20 pm
Location: UK
Score: 23 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest