This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dragengine:modules:dragonscript:behavior_elements [2025/03/10 10:44] – created dragonlord | dragengine:modules:dragonscript:behavior_elements [2025/03/13 23:15] (current) – [XML Element Classes] dragonlord | ||
---|---|---|---|
Line 7: | Line 7: | ||
**Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes. | **Behavior Elements** are build on top of the **Scenery Elements** and provide a **composeable** way to build game logic. This is the fastest way to build your game by befitting elements with reusable **behavior** while still retaining all the powerful coupling to other script classes. | ||
+ | |||
+ | ===== Basics ===== | ||
Behavior elements are created by subclassing from # | Behavior elements are created by subclassing from # | ||
Line 19: | Line 21: | ||
Once a # | Once a # | ||
+ | |||
+ | ===== Behavior Compendium ===== | ||
Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance. | Behaviors are split in two groups: **Basic Behaviors** and **Complex Behaviors**. **Basic Behaviors** add a small basic building block of game logic like for example a component showing the visual appearance of a game object. These are highly reusable. **Complex Behaviors** on the other hand typically expect one or more **Basic Behaviors** to be present in the element class to provide a complex behavior for example animating the visual appearance. | ||
Line 26: | Line 30: | ||
Many more complex behaviors can be created either just for this game project or to be shared with other projects. Behaviors can extend other behaviors by subclassing or by using other behaviors present in the behavior element class. | Many more complex behaviors can be created either just for this game project or to be shared with other projects. Behaviors can extend other behaviors by subclassing or by using other behaviors present in the behavior element class. | ||
+ | |||
+ | ===== Examples ===== | ||
This is an example of an element class which which has a visual appearance, physical interaction, | This is an example of an element class which which has a visual appearance, physical interaction, | ||
+ | ++++ Show Example| | ||
< | < | ||
pin Dragengine.Gui | pin Dragengine.Gui | ||
Line 79: | Line 86: | ||
end | end | ||
</ | </ | ||
+ | ++++ | ||
The above script code creates a working element class which adds instances of BehaviorElement to the game world set up with the defined behaviors. If you want to have a unique element instance for your class to work with you can modify the code like this: | The above script code creates a working element class which adds instances of BehaviorElement to the game world set up with the defined behaviors. If you want to have a unique element instance for your class to work with you can modify the code like this: | ||
+ | |||
+ | ++++ Show Example| | ||
< | < | ||
class MyTrainClass extends BehaviorElementClass | class MyTrainClass extends BehaviorElementClass | ||
Line 95: | Line 105: | ||
end | end | ||
</ | </ | ||
+ | ++++ | ||
Using unique instances allows to add run-time features to your class on top of what BehaviorElement provides without creating an own behavior. In general it is recommended to work with behaviors only and creating your own ones. This way you can reuse game logic across different projects easily. | Using unique instances allows to add run-time features to your class on top of what BehaviorElement provides without creating an own behavior. In general it is recommended to work with behaviors only and creating your own ones. This way you can reuse game logic across different projects easily. | ||
====== XML Element Classes ====== | ====== XML Element Classes ====== | ||
- | TODO | ||
- | ====== Behavior Factories ====== | + | <WRAP center 100%> |
- | TODO | + | <WRAP center box 1050px> |
+ | {{ youtube> | ||
+ | <WRAP centeralign> | ||
+ | Video explaining what behavior factories are, what they can be used for and how they are created. Shown using ExampleApp which contains an example for this.</ | ||
+ | </ | ||
+ | </ | ||
+ | XML Element classes allow to create new element classes using an XML file ('' | ||
+ | |||
+ | Element class properties are typically in the form '' | ||
+ | |||
+ | Behaviors can be complex and nested. This allows behaviors to add other behaviors to achieve their goals. Such nested behaviors need to be differentiated from other behaviors of the same kind. The rule is to prefix the property names of the behaviors with their parent prefix to make them unique. For example if you have a fictional behavior MyBehavior with the prefix '' | ||
+ | |||
+ | ===== Behavior Factories ===== | ||
+ | |||
+ | Scripted element classes can be also assigned a list of # | ||
+ | |||
+ | Adding behaviors is done using the '' | ||
+ | |||
+ | To simplify the adding of behaviors properties of a just added behavior can be also defined by moving the property tags inside the '' | ||
+ | |||
+ | (TODO: add video of behavior factories) | ||
+ | |||
+ | ===== XML File Structure ===== | ||
+ | <uml> | ||
+ | @startuml | ||
+ | object " | ||
+ | <# | ||
+ | |string| | ||
+ | |float| | ||
+ | |integer| | ||
+ | |boolean| | ||
+ | |vector| | ||
+ | |vector2| | ||
+ | |point| | ||
+ | |point3| | ||
+ | |borderSize| | ||
+ | |rectArea| | ||
+ | |floatRectArea| | ||
+ | |color| | ||
+ | |null| | ||
+ | |list|| | ||
+ | |map|| | ||
+ | } | ||
+ | |||
+ | object " | ||
+ | <# | ||
+ | |float| | ||
+ | |integer| | ||
+ | |boolean| | ||
+ | |vector| | ||
+ | |vector2| | ||
+ | |point| | ||
+ | |point3| | ||
+ | |borderSize| | ||
+ | |rectArea| | ||
+ | |floatRectArea| | ||
+ | |color| | ||
+ | |null| | ||
+ | |list|| | ||
+ | |map|| | ||
+ | } | ||
+ | elementClass --> behavior | ||
+ | |||
+ | |||
+ | object " | ||
+ | <# | ||
+ | |float| | ||
+ | |integer| | ||
+ | |boolean| | ||
+ | |vector| | ||
+ | |vector2| | ||
+ | |point| | ||
+ | |point3| | ||
+ | |borderSize| | ||
+ | |rectArea| | ||
+ | |floatRectArea| | ||
+ | |color| | ||
+ | |null| | ||
+ | |list|| | ||
+ | |map|| | ||
+ | } | ||
+ | elementClass --> list | ||
+ | |||
+ | object " | ||
+ | <# | ||
+ | |float| | ||
+ | |integer| | ||
+ | |boolean| | ||
+ | |vector| | ||
+ | |vector2| | ||
+ | |point| | ||
+ | |point3| | ||
+ | |borderSize| | ||
+ | |rectArea| | ||
+ | |floatRectArea| | ||
+ | |color| | ||
+ | |null| | ||
+ | |list|| | ||
+ | |map|| | ||
+ | } | ||
+ | elementClass --> map | ||
+ | |||
+ | @enduml | ||
+ | </ | ||
+ | |||
+ | ===== Tags ===== | ||
+ | |||
+ | ==== elementClass ==== | ||
+ | ^Attribute^Description^Required^Default^ | ||
+ | |name|Unique name of the element class to create.|true|-| | ||
+ | |class|Name of the element class to subclass.|true|-| | ||
+ | |||
+ | ^Tag^Description^Occurance^Default^ | ||
+ | |behavior|Add behavior to element class.|0..N|-| | ||
+ | |string|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |float|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |integer|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |boolean|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |vector|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |vector2|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point3|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |borderSize|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * left: Left value. Optional. Defaults to '' | ||
+ | * top: Top value. Optional. Defaults to '' | ||
+ | * right: Right value. Optional. Defaults to '' | ||
+ | * bottom: Bottom value. Optional. Defaults to '' | ||
+ | * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |rectArea|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |floatRectArea|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |color|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * hex: Set color using hex notation. Value can be ''# | ||
+ | * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |null|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |list|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |map|< | ||
+ | * name: Name of the property to set. Same name as used for stub properties in world editor. Required. | ||
+ | </ | ||
+ | |||
+ | ==== behavior ==== | ||
+ | ^Attribute^Description^Required^Default^ | ||
+ | |type|Unique name of the behavior to add to the element class. Only names matching behavior factories added to the super element class can be used.|true|-| | ||
+ | |id|Unique identifier of behavior. Required to be used if multiple behaviors of the same type are added.|false|empty string| | ||
+ | |||
+ | ^Tag^Description^Occurance^Default^ | ||
+ | |string|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |float|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |integer|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |boolean|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |vector|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |vector2|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point3|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |borderSize|< | ||
+ | * name: Name of the parameter/ | ||
+ | * left: Left value. Optional. Defaults to '' | ||
+ | * top: Top value. Optional. Defaults to '' | ||
+ | * right: Right value. Optional. Defaults to '' | ||
+ | * bottom: Bottom value. Optional. Defaults to '' | ||
+ | * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |rectArea|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |floatRectArea|< | ||
+ | * name: Name of the parameter/ | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |color|< | ||
+ | * name: Name of the parameter/ | ||
+ | * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * hex: Set color using hex notation. Value can be ''# | ||
+ | * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |null|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |list|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |map|< | ||
+ | * name: Name of the parameter/ | ||
+ | </ | ||
+ | |||
+ | ==== list ==== | ||
+ | ^Tag^Description^Occurance^Default^ | ||
+ | |string|String type value. Tag content is string value.|0..N|empty string| | ||
+ | |float|Float type value. Tag content is float value.|0..N|0| | ||
+ | |integer|Integer type value. Tag content is integer value.|0..N|0| | ||
+ | |boolean|Boolean type value. Tag content is boolean value where '' | ||
+ | |vector|< | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |vector2|< | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point|< | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point3|< | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |borderSize|< | ||
+ | * left: Left value. Optional. Defaults to '' | ||
+ | * top: Top value. Optional. Defaults to '' | ||
+ | * right: Right value. Optional. Defaults to '' | ||
+ | * bottom: Bottom value. Optional. Defaults to '' | ||
+ | * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |rectArea|< | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |floatRectArea|< | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |color|< | ||
+ | * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * hex: Set color using hex notation. Value can be ''# | ||
+ | * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |null|Null value.|0..N|-| | ||
+ | |list|Array value.|0..N|-| | ||
+ | |map|Dictionary value.|0..N|-| | ||
+ | |||
+ | ==== map ==== | ||
+ | ^Tag^Description^Occurance^Default^ | ||
+ | |string|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |float|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |integer|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |boolean|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |vector|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |vector2|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |point3|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x: X coordinate of vector. Optional. Defaults to '' | ||
+ | * y: Y coordinate of vector. Optional. Defaults to '' | ||
+ | * z: Z coordinate of vector. Optional. Defaults to '' | ||
+ | </ | ||
+ | |borderSize|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * left: Left value. Optional. Defaults to '' | ||
+ | * top: Top value. Optional. Defaults to '' | ||
+ | * right: Right value. Optional. Defaults to '' | ||
+ | * bottom: Bottom value. Optional. Defaults to '' | ||
+ | * all: Set left, top, right and bottom to the same value. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |rectArea|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |floatRectArea|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * x1: Left value. Optional. Defaults to '' | ||
+ | * y1: Top value. Optional. Defaults to '' | ||
+ | * x2: Right value. Optional. Defaults to '' | ||
+ | * y2: Bottom value. Optional. Defaults to '' | ||
+ | </ | ||
+ | |color|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | * r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to '' | ||
+ | * hex: Set color using hex notation. Value can be ''# | ||
+ | * ir: Red value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ig: Green value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ib: Blue value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | * ia: Alpha value in the range 0..255 with values outside range allowed. Optional. Convenience attribute. | ||
+ | </ | ||
+ | |null|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |list|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |map|< | ||
+ | * key: Key to assign value to. Required. | ||
+ | </ | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | This example creates a simple XML element class based on the # | ||
+ | |||
+ | ++++ Show Example| | ||
+ | <code xml> | ||
+ | <?xml version=' | ||
+ | < | ||
+ | <string name=' | ||
+ | <string name=' | ||
+ | <string name=' | ||
+ | <string name=' | ||
+ | <string name=' | ||
+ | </ | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | This example creates a complex XML element class which is based on the # | ||
+ | |||
+ | ++++ Show Example| | ||
+ | <code xml> | ||
+ | <?xml version=' | ||
+ | < | ||
+ | <!-- | ||
+ | Example element class creating a similar element class as CustomColorExampleClass | ||
+ | but using GenericBehaviorElement as base class and adding behaviors in XML. | ||
+ | Furthermore some additional behaviors are added to show the flexibility of this approach. | ||
+ | --> | ||
+ | |||
+ | <!-- | ||
+ | Add component behavior. This adds a visible presence to the element. Also set some of | ||
+ | the parameters of the behavior. This could be done later in the XML file but it helps | ||
+ | to group the behavior and it's parameters to improve the readability. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | Add collider behavior. This adds physical presence to the element. Adding this behavior | ||
+ | automatically attaches to the component behavior previously added. | ||
+ | --> | ||
+ | < | ||
+ | |||
+ | <!-- | ||
+ | Add navigation space behavior. This adds support for adding navigation space and blockers. | ||
+ | We do not need navigation space but blockers. The behavior automatically uses the previously | ||
+ | added collider behavior. | ||
+ | --> | ||
+ | < | ||
+ | |||
+ | <!-- | ||
+ | In SimpleElementClass used as base class for CustomColorExampleClass the behaviors | ||
+ | ECBehaviorNavigationSpace and ECBehaviorAttachToParent are present too. We do not need | ||
+ | them in this class so we can skip them. | ||
+ | --> | ||
+ | |||
+ | <!-- | ||
+ | Add a couple of custom color behaviors. In SimpleElementClass 5 such behaviors are added. | ||
+ | We do the same thing here. Each behavior requires a unique identifier. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | <color name=' | ||
+ | |||
+ | <!-- | ||
+ | In SimpleElementClass there is also an example to define allowed colors. As mentioned | ||
+ | in the element class limiting to these colors is not implemented. Nevertheless it is | ||
+ | shown here how such a list of colors would be defined. | ||
+ | --> | ||
+ | <list name=' | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <color name=' | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <color name=' | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <color name=' | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <color name=' | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | Add dynamic skin behavior. This allows the textures of the component behavior to be | ||
+ | modified dynamically at runtime. The behavior automatically uses the previously added | ||
+ | component behavior. | ||
+ | --> | ||
+ | < | ||
+ | |||
+ | <!-- | ||
+ | Add renderable canvas behavior. This modifies the " | ||
+ | in the skin file. You need one per renderable you want to modify. Since we use only | ||
+ | one renderable canvas here we are not required to set an identifier. It is though | ||
+ | good practice to set one. This behavior automatically uses the previously added | ||
+ | dynamic skin behavior. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | <point name=' | ||
+ | <color name=' | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | Add behaviors to apply the custom colors to the renderable canvas. These behaviors | ||
+ | automatically use the previously added renderable canvas behavior. Here we have | ||
+ | something new. Some behaviors support (or require) parameters at construction time. | ||
+ | This is done by adding parameter definitions inside the behavior tag. In general the | ||
+ | parameters required to be placed inside the behavior tag can not be changed later on | ||
+ | using regular property definition tags outside the behavior tag. See the respective | ||
+ | Factory inner classes inside the behavior of interest for information on such parameters. | ||
+ | In the case of the ECBehaviorRenderableCustomColor behavior we have to define which | ||
+ | ECBehaviorCustomColor behavior to use. | ||
+ | |||
+ | Because we created above a renderable canvas behavior with a non-empty identifier | ||
+ | we have to define below which renderable canvas we want to use. If the identifier | ||
+ | would be empty (not set) we could remove the renderCanvas string tag and the factory | ||
+ | would use the renderable canvas with the empty identifier. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | Add behavior for player to interact with this element. Adjust the interaction zone | ||
+ | to work with the box. This is a behavior specific to the example application. For this | ||
+ | reason it uses the prefix " | ||
+ | by the Drag[en]gine. Another typical prefix is " | ||
+ | confusion with game world behaviors which use prefix " | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | At this point we have replicated the behaviors present in the SimpleElementClass but | ||
+ | using an XML element class instead of a DragonScript class. The advantage of using | ||
+ | the XML element class way is that no script changes are required. It is also possible | ||
+ | to use automated tools to produce or modify such files. | ||
+ | --> | ||
+ | |||
+ | <!-- | ||
+ | Let's add some more behaviors to extend the element class, even if it is silly. Let's first | ||
+ | add a light near the front side which is red and strong enough against the sun. | ||
+ | --> | ||
+ | < | ||
+ | <float name=' | ||
+ | <float name=' | ||
+ | <float name=' | ||
+ | <color name=' | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | And just because we can also add two particle emitters on top of it. The first one produces | ||
+ | a flame and the second one the smoke. Actually this can be done using a single particle | ||
+ | emitter emitting two types of particles but for this example two emitters are used. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <!-- | ||
+ | And where there is fire should be also sound. Add a speaker behavior with some sound playing. | ||
+ | --> | ||
+ | < | ||
+ | < | ||
+ | <float name=' | ||
+ | <float name=' | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | ++++ | ||