User Tools

Site Tools


dragengine:modules:dragonscript:behavior_twostateanimated

This is an old revision of the document!


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.

ControllerDescription
deactivatedController used while the behavior is in deactivated state. This is typically an unclamped controller. If missing behavior does not think consuming no processing time.
activatedController used while the behavior is in activated state. This is typically an unclamped controller. If missing behavior does not think consuming no processing time.
activatingController 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.
deactivatingController 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:

Instance Counts

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

Element class properties have the prefix twoStateAnimated. or twoStateAnimated({id}). if id is not empty.

animator

Set path to animator to use.

  • Full name: twoStateAnimated.animator or twoStateAnimated({id}).animator
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.deanimator
  • Example (*.deeclass)
    <string name='twoStateAnimated.animator'>default.deanimator</string>

animation

Set path to animation to use. If used replaces animation defined in assigned animators.

  • Full name: twoStateAnimated.animation or twoStateAnimated({id}).animation
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.deanim (all supported animation type modules)
  • Example (*.deeclass)
    <string name='twoStateAnimated.animation'>default.deanim</string>

playSpeed

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.

  • Full name: twoStateAnimated.playSpeed or twoStateAnimated({id}).playSpeed
  • Type: float
  • Default Value: 1
  • Restrictions: At least 0.001
  • Example (*.deeclass)
    <float name='twoStateAnimated.playSpeed'>0.5</float>

trigger

Set trigger. If trigger evaluates to true transitions to active state. If trigger evaluates to false transitions to deactivated state.

  • Full name: twoStateAnimated.trigger or twoStateAnimated({id}).trigger
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='twoStateAnimated.trigger'>@switchOnVent & @powerEnabled</string>

targetActivated

Set activated target. Fires target if state becomes activated. Resets target if state leaves activated.

  • Full name: twoStateAnimated.targetActivated or twoStateAnimated({id}).targetActivated
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='twoStateAnimated.targetActivated'>turnedOn</string>

targetActivating

Set activating target. Fires target while state transitions from deactivated to activated state. Resets target if state becomes activated.

  • Full name: twoStateAnimated.targetActivating or twoStateAnimated({id}).targetActivating
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='twoStateAnimated.targetActivating'>turningOn</string>

targetDeactivating

Set deactivating target. Fires target while state transitions from activated to deactivated state. Resets target if state becomes deactivated.

  • Full name: twoStateAnimated.targetDeactivating or twoStateAnimated({id}).targetDeactivating
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='twoStateAnimated.targetDeactivating'>turningOff</string>

Events

This behavior has these events:

startActivate

Start transition from deactivated state to activated state.

stopActivate

Finished transition from deactivated state to activated state.

startDeactivate

Start transition from activated state to deactivated state.

stopDeactivate

Finished transition from activated state to deactivated state.

updateControllers

Update controllers if required.

animationApplied

Animation has been applied.

Behavior Tree Actions

This behavior adds these behavior tree actions if behavior tree is present. If behavior has non-empty identifier replace twoStateAnimated with twoStateAnimated(id).

twoStateAnimated.set

Set one or more two-state animated parameters.

ParameterValueDescription
activate If in deactivated state start transition to activated state
deactivate If in activated state start transition to deactivated state
reverse.activating If activating switches to deactivating with deactivate progress set to reversed activate progress
reverse.deactivating If deactivating switches to activating with activate progress set to reversed deactivate progress
set.deactivated Set to deactivated state
set.activating Set to activating state at 0% progress
set.activated Set to activated state
set.deactivating Set to deactivating state at 0% progress

This is an example of using this action:

<action name='twoStateAnimated.set'>
  <parameter name='activate'/>
</action>

twoStateAnimated.check

Check one or more two-state animated. Action succeeds if all parameter value matches their respective twoStateAnimated parameter otherwise action fails. This action is typically used as first action in a sequence to run the sequence only if a twoStateAnimated parameter matches (or not).

ParameterValueDescription
deactivatedtrue, falseAnimation state is deactivated
activatedtrue, falseAnimation state is activated
activatingtrue, falseAnimation state is activating
deactivatingtrue, falseAnimation state is deactivating
progress.activate.lessfloatActivation progress is less than value in the range from 0 to 1
progress.activate.greaterfloatActivation progress is greater than value in the range from 0 to 1
progress.deactivate.lessfloatDeactivation progress is less than value in the range from 0 to 1
progress.deactivate.greaterfloatDeactivation progress is greater than value in the range from 0 to 1

This is an example of using this action:

<sequence>
  <action name='twoStateAnimated.check'>
    <parameter name='activating'>true</parameter>
    <parameter name='progress.activate.less'>0.5</parameter>
  </action>
  <!-- actions here run only if behavior is activating with less than 50% done -->
</sequence>

Behavior Tree Conditions

This behavior adds these behavior tree conditions if behavior tree is present. If behavior has non-empty identifier replace twoStateAnimated with twoStateAnimated(id).

twoStateAnimated.check

Check one or more two-state animated. Conditions returns true if all parameter value match their respective twoStateAnimated parameter. This condition is typically used to run an action or sequence of actions as long as twoStateAnimated conditions are true.

ParameterValueDescription
twoStateAnimated.deactivatedtrue, falseAnimation state is deactivated
twoStateAnimated.activatedtrue, falseAnimation state is activated
twoStateAnimated.activatingtrue, falseAnimation state is activating
twoStateAnimated.deactivatingtrue, falseAnimation state is deactivating
twoStateAnimated.progress.activate.lessfloatActivation progress is less than value in the range from 0 to 1
twoStateAnimated.progress.activate.greaterfloatActivation progress is greater than value in the range from 0 to 1
twoStateAnimated.progress.deactivate.lessfloatDeactivation progress is less than value in the range from 0 to 1
twoStateAnimated.progress.deactivate.greaterfloatDeactivation progress is greater than value in the range from 0 to 1

This is an example of using this condition:

<action name='myAction' id='doing something'>
  <parameter name='twoStateAnimated.activating'>true</parameter>
  <parameter name='twoStateAnimated.progress.activate.less'>0.5</parameter>
  <condition>twoStateAnimated.check</condition>
</action>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

This behavior does support element class to be persistable (setPersistable).

API Documentation

ECBehaviorTwoStateAnimated.

Since DragonScript Module Version 1.0

Use Cases

  • Animate object which can switch between activated and deactivated state with transition animations.

Element Class Example

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

Behavior Factory

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: identifier of ECBehaviorTriggered to synchronize with or empty
                   string to not synchronize. default is empty string. -->
    <string name='trigger.synchronize'>other</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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_twostateanimated.1746112321.txt.gz · Last modified: 2025/05/01 15:12 by dragonlord