{{tag>dragonscript behavior}} [[:start|Start Page]] >> [[main|DragonScript Scripting Language]] >> [[dragengine:modules:dragonscript:abstractions|Abstraction Layers: How you want to build your Game]] >> [[dragengine:modules:dragonscript:behavior_elements|Behavior Elements]] >> **ECBehaviorTwoStateAnimated** * [[behaviors_use_cases|Behaviors Explained: By Use-Case]] * [[behaviors_a_to_z|Behaviors Explained: From A to Z]] ====== 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: * [[gamedev:animators|Animators and Animations]] * [[gamedev:deigde:editors:animator|IGDE Animator Editor]] * [[tools:blenderexportscripts|Blender3D Export Scripts]] ====== Instance Counts ====== Multiple ECBehaviorTwoStateAnimated can be added targeting different [[behavior_component|ECBehaviorComponent]] using their identifier. It is also possible to add multiple ECBehaviorTwoStateAnimated manipulating the same [[behavior_component|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) default.deanimator ===== 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) default.deanim ===== 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) 0.5 ===== 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) @switchOnVent & @powerEnabled ===== 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) turnedOn ===== 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) turningOn ===== 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) turningOff ====== 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. ====== Required Behaviors ====== * [[behavior_component|ECBehaviorComponent]] ====== Optional Behaviors ====== This behavior does not support optional behaviors. ====== Persistency ====== This behavior does support element class to be persistable (setPersistable). ====== API Documentation ====== #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECBehaviorTwoStateAnimated.html,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: second default deactivated activated activating deactivating flap.deanimator ====== Live Examples ====== * [[https://github.com/LordOfDragons/deexamples|DEExamples Repository]]