Game Development Community

Play 3D sound

by Blackcode · in Torque Game Engine · 05/30/2007 (8:33 am) · 1 replies

When I use the following code the engine crashed, any idea ?

%whichdoor.openSnd = %whichdoor.playAudio(0, doorStartOpenSwingSnd);

//sound proifle
datablock AudioProfile(doorStartOpenSwingSnd)
{
fileName = "~/data/sound/door1_move.wav";
description = AudioOpen3d;
preload = true;
};

thanks

#1
05/30/2007 (11:21 am)
To play a sound (am i'm no expert so there may be easier or better way) you can do this: (This may or may not be what your looking for... )

Create a new audio description & audio profile: client/audioProfiles.cs

datablock AudioDescription(OpenDoorDescription)
{
 	volume = 1.0;
	isLooping= false;
	is3D = true;
	ReferenceDistance= 20.0;
	MaxDistance= 100.0;
	type = $SimAudioType;
};

datablock AudioProfile(OpenDoorProfile)
{
	filename = "~/data/sound/door1_move.wav";
	description = "OpenDoorDescription";
	preload = true;
};

Then on the clientside add a function to play your sound: client/game.cs

function clientCmdPlayDoorSound()
{
	$doorSound = alxPlay(OpenDoorProfile);
}

Now use a command to client to play the sound when you need to: (where %cl is the clientID)

commandToClient(%cl, 'PlayDoorSound');

or you could make it a function and call it .... something like:

function startDoorSound()
{
   // Tell the client to count.
   for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
      %cl = ClientGroup.getObject( %clientIndex );
      commandToClient(%cl, 'PlayDoorSound');
   }
}

(edit)

Then when you need to stop the sound you can then use:

alxStop($doorSound);