Start Page » DragonScript Scripting Language » Behavior Elements: Quick and Easy Development » ECBehaviorTwoStateAnimated
Behavior element behavior adding two state animation support.
Plays back animations for behavior elements in two different states with transition between them. Animators are required to have controllers name the right way to work with this behavior. Controllers not matching the require name are ignored. It is not necessary to have all controller names covered. Actually this behavior optimizes at runtime if not all controllers are used.
Controller | Description |
---|---|
deactivated | Controller used while the behavior is in deactivated state. This is typically an unclamped controller. If missing behavior does not think consuming no processing time. |
activated | Controller used while the behavior is in activated state. This is typically an unclamped controller. If missing behavior does not think consuming no processing time. |
activating | Controller used while behavior is transitioning from deactivated state to activated state. The transition ends when the controller reaches the upper limit. For this reason the controller has to be a clamped controller otherwise the transition never ends. If missing behavior transitions immediately to activated state. |
deactivating | Controller used while behavior is transitioning from activated state to deactivated state. The transition ends when the controller reaches the upper limit. For this reason the controller has to be a clamped controller otherwise the transition never ends. If missing behavior transitions immediately to deactivated state. |
The controller names can be changed using the setControllerName*() methods.
Activate Trigger
When changing to true the element is switched to the activated state. When changing to false the element is switched to the deactivated state. If the switch happens during transition time the transition is finished before switching.
See also:
Multiple ECBehaviorTwoStateAnimated can be added targeting different ECBehaviorComponent using their identifier. It is also possible to add multiple ECBehaviorTwoStateAnimated manipulating the same ECBehaviorComponent as long as the animators used are properly crafted. This can be used for example to add overlayed animations.
Element class properties have the prefix twoStateAnimated.
or twoStateAnimated({id}).
if id is not empty.
Set path to animator to use.
twoStateAnimated.animator
or twoStateAnimated({id}).animator
*.deanimator
<string name='twoStateAnimated.animator'>default.deanimator</string>
Set path to animation to use. If used replaces animation defined in assigned animators.
twoStateAnimated.animation
or twoStateAnimated({id}).animation
*.deanim
(all supported animation type modules)<string name='twoStateAnimated.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.
twoStateAnimated.playSpeed
or twoStateAnimated({id}).playSpeed
<float name='twoStateAnimated.playSpeed'>0.5</float>
Set trigger. If trigger evaluates to true transitions to active state. If trigger evaluates to false transitions to deactivated state.
twoStateAnimated.trigger
or twoStateAnimated({id}).trigger
<string name='twoStateAnimated.trigger'>@switchOnVent & @powerEnabled</string>
Set activated target. Fires target if state becomes activated. Resets target if state leaves activated.
twoStateAnimated.targetActivated
or twoStateAnimated({id}).targetActivated
<string name='twoStateAnimated.targetActivated'>turnedOn</string>
Set activating target. Fires target while state transitions from deactivated to activated state. Resets target if state becomes activated.
twoStateAnimated.targetActivating
or twoStateAnimated({id}).targetActivating
<string name='twoStateAnimated.targetActivating'>turningOn</string>
Set deactivating target. Fires target while state transitions from activated to deactivated state. Resets target if state becomes deactivated.
twoStateAnimated.targetDeactivating
or twoStateAnimated({id}).targetDeactivating
<string name='twoStateAnimated.targetDeactivating'>turningOff</string>
This behavior has these events:
Start transition from deactivated state to activated state.
Finished transition from deactivated state to activated state.
Start transition from activated state to deactivated state.
Finished transition from activated state to deactivated state.
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).
Since DragonScript Module Version 1.0
This example defines an element which suports two-state animation.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) ECBehaviorTwoStateAnimated.new(this, "color1", "Color 1", Color.blue) ECBehaviorTwoStateAnimated.new(this, "color2", "Color 2", Color.red) 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='ECBehaviorTwoStateAnimated'> <!-- 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: name of deactivated controller. default is 'deactivated' --> <string name='controllerNameDeactivated'>deactivated</string> <!-- optional: name of activated controller. default is 'activated' --> <string name='controllerNameActivated'>activated</string> <!-- optional: name of activating controller. default is 'activating' --> <string name='controllerNameActivating'>activating</string> <!-- optional: name of deactivating controller. default is 'deactivating' --> <string name='controllerNameDeactivating'>deactivating</string> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.animator'>flap.deanimator</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorTwoStateAnimated' id='second'/> </elementClass>