User Tools

Site Tools


dragengine:modules:dragonscript:behavior_animated

This is an old revision of the document!


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.

Because multiple animator behaviors can animate the same component behavior the animator behavior has an own identifier. In the example above the first string parameter is the animator behavior identifier while the second string parameter is the component behavior identifier to animate.

See also:

Instance Counts

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

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

path

Set path to animator to use.

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

animation

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

  • Full name: animated.animation or animated({id}).animation
  • Type: string
  • Default Value: empty string
  • Expected File Pattern: *.deanim (all supported animation type modules)
  • Example (*.deeclass)
    <string name='animated.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: animated.playSpeed or animated({id}).playSpeed
  • Type: float
  • Default Value: 1
  • Example (*.deeclass)
    <float name='animated.playSpeed'>0.5</float>

playing

Set if animator is playing back after creating element.

  • Full name: animated.playing or animated({id}).playing
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='animated.playing'>false</boolean>

playbackController

Set name of controller used to play back the animation. Controller value is incremended by elapsed time multiplied by playSpeed.

  • Full name: animated.playbackController or animated({id}).playbackController
  • Type: string
  • Default Value: playback
  • Example (*.deeclass)
    <string name='animated.playbackController'>animation</string>

move

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.

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

loopMove

Set loop animation move. Used only if animator is not set and animation and move is set.

  • Full name: animated.loopMove or animated({id}).loopMove
  • Type: boolean
  • Default Value: true
  • Example (*.deeclass)
    <boolean name='animated.loopMove'>false</boolean>

trigger

Set trigger playing back. If no trigger is set the state of playing property is used.

  • Full name: animated.trigger or animated({id}).trigger
  • Type: string
  • Default Value: state of playing
  • Example (*.deeclass)
    <string name='animated.trigger'>@machineOn & @powerEnabled</string>

targetPlaying

Set playing target. If playing starts target is fired. If playing stops target is reset.

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

applyPostThink

Set apply animator during postThink() instead of think().

  • Full name: animated.applyPostThink or animated({id}).applyPostThink
  • Type: boolean
  • Default Value: false
  • Example (*.deeclass)
    <boolean name='animated.applyPostThink'>true</boolean>

Events

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:

startPlaying

Start playing back.

stopPlaying

Stop playing.

updateControllers

Update controllers if required.

animationApplied

Animation has been applied.

Required Behaviors

This behavior requires these other behaviors:

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

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

API Documentation

ECBehaviorAnimated.

Since DragonScript Module Version 1.0

Use Cases

  • Allow actor to style his player actor using custom colors for individual body parts.
  • Create variations of NPCs by adding color slots that can be modified in XML Element Classes or using Stub Properties.

Element Class Example

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

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='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>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_animated.1741790599.txt.gz · Last modified: 2025/03/12 14:43 by dragonlord