Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorAnimated
Behavior element behavior adding animation support.
Playing back an animation using an animator for an ECBehaviorComponent. By default the ECBehaviorComponent with empty identifier is animated.
To use this behavior make sure to add first the ECBehaviorComponent to animate.
See also:
Multiple ECBehaviorAnimated can be added targeting different ECBehaviorComponent using their identifier. It is also possible to add multiple ECBehaviorAnimated manipulating the same ECBehaviorComponent as long as the animators used are properly crafted. This can be used for example to add overlayed animations like gestures onto an actor.
Element class properties have the prefix animated.
or animated({id}).
if id is not empty.
Set path to animator to use.
animated.path
or animated({id}).path
*.deanimator
<string name='animated.path'>default.deanimator</string>
Set path to animation to use. If used replaces animation defined in assigned animators.
animated.animation
or animated({id}).animation
*.deanim
(all supported animation type modules)<string name='animated.animation'>default.deanim</string>
Set playback speed. Value of 1
plays back at normal speed. Values larger than 1 play back faster. Values less then 1 play back slower.
animated.playSpeed
or animated({id}).playSpeed
<float name='animated.playSpeed'>0.5</float>
Set if animator is playing back after creating element.
animated.playing
or animated({id}).playing
<boolean name='animated.playing'>false</boolean>
Set name of controller used to play back the animation. Controller value is incremended by elapsed time multiplied by playSpeed
.
animated.playbackController
or animated({id}).playbackController
playback
<string name='animated.playbackController'>animation</string>
Set move name. If animator is not set this creates a temporary animator with a single animation type rule playing back move
. This can be used to play animation moves without needing to create an animator.
animated.move
or animated({id}).move
<string name='animated.move'>idle</string>
Set loop animation move. Used only if animator is not set and animation and move is set.
animated.loopMove
or animated({id}).loopMove
true
<boolean name='animated.loopMove'>false</boolean>
Set trigger playing back. If no trigger is set the state of playing
property is used.
animated.trigger
or animated({id}).trigger
playing
<string name='animated.trigger'>@machineOn & @powerEnabled</string>
Set playing target. If playing starts target is fired. If playing stops target is reset.
animated.targetPlaying
or animated({id}).targetPlaying
<string name='animated.targetPlaying'>animationPlaying</string>
Set apply animator during postThink() instead of think().
animated.applyPostThink
or animated({id}).applyPostThink
false
<boolean name='animated.applyPostThink'>true</boolean>
Behavior elements and other behaviors can add listeners to the ECBehaviorAnimated. Listeners are notified if the animation starts playing and when it stops playing. This can be used to synchronize actions to these events. ECBehaviorAnimated can also use trigger targets so listeners are not always required.
Another use for listeners is update animator controllers not handled by ECBehaviorAnimated itself. ECBehaviorAnimated calls AnimatorInstance.apply() before it exits thinking. If other behaviors modify the animator controller later on they need to call AnimatorInstance.apply() again. If multiple behaviors affect the same animated component this can put strain on the game engine modules and reduce performance. For this reason listeners are also asked to update animator controllers. This allows multiple behaviors to update individual controllers with AnimatorInstance.apply() to be called only once.
It is important to note that using listeners behaviors are asked to update animator controllers before their think() method is called. For such behaviors it is best to do their thinking inside the listener call avoiding think() to be used at all.
A typical usage pattern for such behaviors is to locate the animator controller to update during construction time and to manipulated the controllers inside updateControllers().
See Element Class Example for example code.
This behavior has these events:
Start playing back.
Stop playing.
Update controllers if required.
Animation has been applied.
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable). Saves selected color.
Since DragonScript Module Version 1.0
This example defines an element which supports being animated.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorAnimated animated func new() component = ECBehaviorComponent.new(this, null) animated = ECBehaviorAnimated.new(this, component) end end
Example of using listeners.
class MyListener extends ECBehaviorInstance.DefaultListener var AnimatorController pController func new(ECBehaviorAnimated behavior) pController = behavior.getAnimatorInstance().getControllerNamed("special controller") end func void updateControllers(Instance instance, float elapsed) pController.increment(elapsed) 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='ECBehaviorComponent'/> <behavior type='ECBehaviorAnimated'> <!-- optional: use component with id instead of empty string --> <string name='component'>second</string> <!-- optional: use BaseGameApp trigger table. game can add more supported values. default is 'default' --> <string name='triggerTable'>default</string> <!-- optional: use named controller instead of first controller. default is empty string --> <string name='controllerName'>playback</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.path'>default.deanimator</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorAnimated' id='second'/> </elementClass>