Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorComposed
Behavior for element allowing to create and add child elements.
This behavior is useful to create element classes which automatically create and attach child elements without using the world editor.
This behavior defines a list of element classes to use. For each element class an optional list of property values can be defined that are used to create an instance of this class.
This behavior can be used only once on an element.
Element class properties have the prefix composed.
.
Set child elements to create. This is a list of map entries for each child element. Children are created in the order they are defined. The map entry requires at least a string value with name class
indicating the element class to use. Optionally a list value with name properties
can be used containing stub element properties to use for creating the element. Values in this list are string values where the name is the property key and the string value is the property value.
composed.children
Example (*.deeclass)
<list name='composed.children'> <map> <string key='class'>Backpack</string> <list key='properties'> <string key='attachToParent.attachSlot'>backpack</string> </map> </map> </list>
This behavior has no events.
This behavior requires no other behaviors.
This behavior does not support optional behaviors.
This behavior does support element class to be persistable (setPersistable). Saves if children elements have been already created.
Since DragonScript Module Version 1.0
This example defines an element which contains a single child element which is a backpack.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorComposed composed func new() // add component which contains a rig with the bone 'backpack' component = ECBehaviorComponent.new(this, null) // add collider to have something to attach children to collider = ECBehaviorCollider.new(this, component) // add composed behavior and add a child definition to it composed = ECBehaviorComposed.new(this) var Dictionary child = Dictionary.new() child.setAt("class", "MyBackpackClass") var Dictionary properties = Dictionary.new() properties.setAt("attachToParent.attachSlot", "backpack") child.setAt("properties", properties) composed.getChildren().add(child) 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'> <!-- add component which contains a rig with the bone 'backpack' --> <behavior type='ECBehaviorComponent'/> <!-- add collider to attach children to --> <behavior type='ECBehaviorCollider'/> <!-- add composed behavior --> <behavior type='ECBehaviorComposed'> <!-- set element properties. omit property prefix if used inside behavior tag --> <list name='.children'> <!-- define a backpack element to be added --> <map> <!-- the class name of the element to add --> <string key='class'>Backpack</string> <!-- list of element properties to set for the added element --> <list key='properties'> <!-- attach element to component bone named 'backpack' --> <string key='attachToParent.attachSlot'>backpack</string> </map> </map> </list> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorComposed' id='second'/> </elementClass>