Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorFootSteps
Behavior element behavior adding foot steps support to actors.
Uses a list of events to play random foot steps according to an elapsing time value. The elapsed time is updated with the elapsed game time while the actor is walking. If auto-update is true (which is the default) update() is called automatically by the behavior on thinking. Otherwise the actor has to call update(float) to advance the elapsed time. Independent of auto-updating the actor has to call reset() when standing still to ensure the events fire at the right time.
Events define for an elapsed time the sound to play. This is using a WeightedRandomList allowing to pick a random sound with support to favor certain sounds. The sound is then played at an offset relative to the behavior element with individual sound parameters. The sound parameters and offset are defined for each individual sound allowing special configurations like a pirate walking with a wooden leg.
It is common for actors to switch between different gaits (walking, running, robbing or sneaking). To make this process simple multiple configurations can be stored. The actor can then switch between configurations. Depending on how the animations are set up for the actor changing configuration has to reset the elapsed time or not. The actor is responsible to call reset() if required after switching configurations.
If you want to support different foot step sounds for different materials you should not use multiple configurations since switching them can reset the event timing. Use instead events with empty sound list and use the behavior listener to be notified when sound has to be played. See other behaviors for adding material foot step support as well as other special effects like triggering particle emitters.
This behavior can be used only once on an element.
Element class properties have the prefix footSteps.
.
This behavior has these events:
Foot step triggered.
Configuration changed.
This behavior requires no other behaviors.
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which has support for playing footsteps.
class MyElement extends BehaviorElementClass public var ECBehaviorFootSteps footSteps func new() footSteps = ECBehaviorFootSteps.new(this, "color1", "Color 1", Color.blue) end end
Using element class supporting adding behaviors the behavior can be added like this:
<?xml version='1.0' encoding='UTF-8'?> <elementClass name='MyClass' class='GenericBehaviorElement'> <behavior type='ECBehaviorFootSteps'> <!-- set if update() is automatically called on postThink(). default is 'true' --> <boolean name='autoUpdate'>false</boolean> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.name'>value</string> </behavior> </elementClass>