At 7/30/06 02:46 AM, -Jindo- wrote:
I'm just wondering if any one knows of a decent method to use :)
I almost always use the
myeffect=new Sound();
myeffect.attachSound("libraryname");
myeffect.start();
method.
If you do use that method you have a couple of options to avoid repeating the sound when you don't want to:
1. The .position property: Basically it'll tell you the position of a sound object in milliseconds so if the position is not at 0 it's already playing. ie:
if (myeffect.position==0)
{
myeffect.start();
}
//I haven't actually tested this so who knows if it'll actually work
2. The onSoundComplete() function. Basically you can set any sound object to run a function when it gets to the end so you can set a variable to true when the sound starts and have it automatically return to false when the sound ends. ie:
if (!isplaying && Key.isDown(Key.SPACE))
{
myeffect.start();
isplaying=true;
myeffect.onSoundComplete=function ()
{
isplaying=false;
}
}
I've never worried about it much though because usually sound fx are short enough that having them overlap actually sounds fine.
Oh, and you can also use the stopAllSounds() function before running a new sound if worse comes to worst (but that would stop any looping bg music too, so be careful).