Game Development Community

OnWorldLimit

by Bruno · in Torque Game Builder · 12/18/2005 (7:26 am) · 7 replies

Hi.,

I'm playing a sound, in a loop that starts when a entity shows in the screen.
When this entity is either killed or off the screen, i want to stop the sound from playing.
What i'm doing, is the following :

In the entity creation function :

%enemy.setWorldLimit( kill,"-230 -110 230 110", 1);
alxPlay(shipAudio);

And i setup the callback, like this :

function fxSceneObject2D::onWorldLimit( %srcObj, %limitMode, %limit)
{
 alxStop(shipAudio);
}

What am i doing wrong ?
The sound should stop, in the minute the entity leaves the screen., so i must be setting up the callback in a wrong way..,

thanks,
Bruno

#1
12/18/2005 (7:39 am)
Actually, i just added a "echo" in the onWorldLimit function, and she indeed is called, just the alxStop is not working, as the sound continues to play.., the sound is audioloop, but that shouldn't make a diference
#2
12/18/2005 (7:43 am)
Maybe this thread will help you:

Thread Link
#3
12/18/2005 (7:48 am)
Can't open it.., i don't own TGE, only T2D .., can you post the relevant parts here ??
#4
12/18/2005 (8:25 am)
I replaced alxStop(shipAudio); with alxStopAll(), and it worked, all sounds stopped., so it seams the problem is with alxStop.., whats wrong with it ? am i using it in a wrong way ?

thanks,
Bruno
#5
12/18/2005 (8:36 am)
The problem is that you're not using it correctly. "alxPlay()" returns you a handle which you can use in the other alx-functions including "alxStop()". Use it like this...

// Start the sound.
%audioID = alxPlay(shipAudio);
// ...
// ...
// ...
// Stop the sound.
alxStop(%audioId);
Typically, you assign the ID to the associated object for easy tracking so in your example, you'd probably want to store it against the "ship" object like so...
// Start the sound.
$playerShip.audioID = alxPlay(shipAudio);
// ...
// ...
// ...
// Stop the sound.
alxStop($playerShip.audioId);
... or to be extra safe...
// Start the sound.
$playerShip.audioID = alxPlay(shipAudio);
// ...
// ...
// ...
// Stop the sound (if it's playing)
if ( alxIsPlaying($playerShip.audioId) )
{
    alxStop($playerShip.audioId);
}

This makes sense as you may want to play an item more than once simultaneously and stop each one individually.

If you look in "audioFunctions.cc", you'll find the other alx-functions and most take the handle described above.

Hope this helps,

- Melv.
#6
12/18/2005 (8:48 am)
Yup, works well :)
thanks Melv
#7
12/18/2005 (10:58 am)
You're welcome. :)

- Melv.