sounds question

Game Editor comments and discussion.

sounds question

Postby Nykos » Tue Feb 07, 2012 2:42 pm

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.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: sounds question

Postby Game A Gogo » Tue Feb 07, 2012 5:11 pm

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!
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: sounds question

Postby Nykos » Wed Feb 08, 2012 4:25 am

tank you man, will try it :)
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: sounds question

Postby Nykos » Wed Feb 08, 2012 6:25 am

doesn't change a thing, passed a moment, stopSound just doesn't work anymore
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: sounds question

Postby skydereign » Wed Feb 08, 2012 7:35 am

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/
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: sounds question

Postby Nykos » Wed Feb 08, 2012 9:02 am

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.:)
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score

Re: sounds question

Postby skydereign » Wed Feb 08, 2012 11:34 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: sounds question

Postby Nykos » Thu Feb 09, 2012 4:38 am

thank you Sky, will have a look at it today.
Nykos
 
Posts: 110
Joined: Sun Dec 19, 2010 11:11 pm
Score: 6 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest