Table of Contents

,

Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorAnimated

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:

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.

animation

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

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.

playing

Set if animator is playing back after creating element.

playbackController

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

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.

loopMove

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

trigger

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

targetPlaying

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

applyPostThink

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

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

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

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

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

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