Turning off weapon state sounds
by Shai Perry · in Torque Game Engine · 06/08/2006 (5:46 pm) · 3 replies
I was wondering if it's possible when I'm in a given state to turn off a previous state's sound in ShapeBaseImageData.
For example let's say I'm in state 2 and I have "stateSound[2] = SomeLongSound;" and then I switch to state 3 it still finishes the sound that was playing in state 2 whereas I want it to completely turn off when I switch states.
I tried setting the state 3 sound to "stateSound[3] = BlankSound" where BlankSound is just a blank .ogg.
But it didn't work.
Any Ideas?
Thanks
For example let's say I'm in state 2 and I have "stateSound[2] = SomeLongSound;" and then I switch to state 3 it still finishes the sound that was playing in state 2 whereas I want it to completely turn off when I switch states.
I tried setting the state 3 sound to "stateSound[3] = BlankSound" where BlankSound is just a blank .ogg.
But it didn't work.
Any Ideas?
Thanks
Torque Owner Tim Heldna
I reworked this code to use one audio channel only and use singular (non-looped) sounds.
The result is a much cleaner and clearer sounding weapon.
Engine\Game\ShapeImage.cc
Lines at approx 1616 look like this:
// Play sound if (stateData.sound && isGhost()) { Point3F vel = getVelocity(); image.animSound = alxPlay(stateData.sound, &getRenderTransform(), &vel); ALint value = 0; alxGetSourcei(image.animSound, AL_LOOPING, &value); image.animLoopingSound = (value == AL_TRUE); }Replace with this:
// Play sound if (stateData.sound && isGhost()) { Point3F vel = getVelocity(); if(image.animSound) { alxStop(image.animSound); image.animSound = 0; } image.animSound = alxPlay(stateData.sound, &getRenderTransform(), &vel); ALint value = 0; //alxGetSourcei(image.animSound, AL_LOOPING, &value); image.animLoopingSound = false;//(value == AL_TRUE); }What this does is plays a sound and, if that sound is still playing when the next firing sound is played, it stops it before playing the next sound.
This means you can use a nice long 2 second rifle sound in an automatic rifle (if you wish)
and the last firing sound will have that nice long fade.