Page 1 of 1

sounds question

PostPosted: Tue Feb 07, 2012 2:42 pm
by Nykos
hi guys, I'm actualy in the worst part of creating a game for me, chosing andsetting up sounds...
So , for once, i'd like it to sound good and i'm trying to use stopSound. I understand most of how it works, but still have some problems with it.

I have an actor with a mousebuttondown event that , when clicked, plays a sound. And a mousebuttonup that has a stopSound. At this stage, it works. But when i have other sounds played from other actors, it stops the other sounds too. Which is not what i want.

I understand that this must be a chanel problem. And here is my question. Is there a way to have each sounds on different channels? So that i can stop some sounds, and not others, depending on which action i'm doing.

And, just in case, does someone know some free commercial use music, i'm so bad at this kind of stuff.

Re: sounds question

PostPosted: Tue Feb 07, 2012 5:11 pm
by Game A Gogo
Go into Config -> Game Properties and change the maximum of simultaneous sounds, which means the number of channels there is. By default this is 8, which is very low!

Re: sounds question

PostPosted: Wed Feb 08, 2012 4:25 am
by Nykos
tank you man, will try it :)

Re: sounds question

PostPosted: Wed Feb 08, 2012 6:25 am
by Nykos
doesn't change a thing, passed a moment, stopSound just doesn't work anymore

Re: sounds question

PostPosted: Wed Feb 08, 2012 7:35 am
by skydereign
So you have been saving the channel appropriately? Since PlaySound2 returns the channel it uses, you'll have to use that. But, there is the problem that when the sound finishes, a new sound can take the channel, which means you'll have to make sure not to stop the new sound. Also if the sound gets stopped on the mouse button down, you need to increase the number of max sounds, otherwise it seems you are not recording/using the right channels for stopSound. And DST made a lot of music you can use in your games.
http://www.nosoapradio.us/

Re: sounds question

PostPosted: Wed Feb 08, 2012 9:02 am
by Nykos
Saving chanels appropriately? I'm sorry, but honestly i have no clue how to do it. But since new sounds take the chanels, i think i'll do without stop sound, i just have to re-think it a bit. But if you have the time to to explain it sky, every knowledge is good to take.:)

Re: sounds question

PostPosted: Wed Feb 08, 2012 11:34 pm
by skydereign
Well the idea is that stopSound stops the sound in a certain channel. So if you wanted to stop a sound, you would need to know what channel it is playing in. Because of that, you need some way of saving the channel returned when the original PlaySound2 call was made (since it returns the channel it plays in). So by saving channels I just mean knowing which channel to use in stopSound via some form of variable. But when you do this, you also have to keep in mind two things.

First is if PlaySound2 for some reason doesn't work. In that case it returns a 0, and as you know, if you try to stopSound(0), everything but the music will stop. A way to work around this is to check if the sound you are about to stop is not 0 before stopping it. You can write a convenient wrapper for that.
Global Code
Code: Select all
void
stopSound2 (int channel)
{
    if(channel != 0)
    {
        stopSound(channel);
    }
})


The second problem is a little harder to deal with. Since there are a limited number of channels, the sounds will reuse old channels. So even if you are storing the channels from PlaySound2 properly, if the sound ends and a new sound is put into the channel you'll have problems. You could set up a sound control system that tracks the channels in use and have them reset through timer event when the sound finishes. Implementation depends on how you are storing and stopping the sounds though.

Re: sounds question

PostPosted: Thu Feb 09, 2012 4:38 am
by Nykos
thank you Sky, will have a look at it today.