Using triggers to play sound
by Frankie Lee Stephenson II · in General Discussion · 09/05/2007 (11:59 am) · 2 replies
I need to know how to make tiggers call sound into Torque
About the author
#2
09/05/2007 (6:57 pm)
Here's one i did.//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//-----------------------------------------------------------------------------
//Modified by MikeR
//-----------------------------------------------------------------------------
//my sound for this trigger
new AudioProfile(WaterSplashSound)
{
filename = "~/data/sound/water1.ogg";
description = "AudioSoftLooping2D";
preload = true;
};
//my function for playing this sound
//-----------------------------------------------------------------------------
// DefaultTrigger is used by the mission editor. This is also an example
// of trigger methods and callbacks.
datablock TriggerData(waterSoundTrigger)
{
// The period is value is used to control how often the console
// onTriggerTick callback is called while there are any objects
// in the trigger. The default value is 100 MS.
tickPeriodMS = 100;
};
//-----------------------------------------------------------------------------
function waterSoundTrigger::onEnterTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object enters the %trigger
// area, the object is passed as %obj. The default onEnterTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onEnterTrigger(%this,%trigger,%obj);
$MusicHandle =alxPlay(WaterSplashSound);
echo("\nEntering waterSound trigger area");
}
function waterSoundTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
// This method is called whenever an object leaves the %trigger
// area, the object is passed as %obj. The default onLeaveTrigger
// method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
// every object (whatever it's type) in the same group as the trigger.
Parent::onLeaveTrigger(%this,%trigger,%obj);
alxStop ($MusicHandle );
echo("\nExiting waterSound trigger area");
}
function waterSoundTrigger::onTickTrigger(%this,%trigger)
{
// This method is called every tickPerioMS, as long as any
// objects intersect the trigger. The default onTriggerTick
// method (in the C++ code) invokes the ::onTriggerTick(%trigger) method on
// every object (whatever it's type) in the same group as the trigger.
// You can iterate through the objects in the list by using these
// methods:
// %this.getNumObjects();
// %this.getObject(n);
Parent::onTickTrigger(%this,%trigger);
}
Torque 3D Owner mb