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 BehaviorElementClass script class. This class extends the ElementClass script class with support to add Behavior Definitions. When a BehaviorElement instance is created these behavior definitions are used to befit the element with all the required functionality. All this can be done manually by using Scenery Elements but using Behavior Elements this boils down to just adding the behavior definitions you like to use.
Behavior definitions are created by subclassing from ECBehavior script class. This stands for Element Class Behavior. Behavior definitions typically contain Composeable Element Class or Element Class Property instances with appropriate parameters set. This has a few nice properties making life simpler.
Element class properties can be used with XML Subclassing. You can created a new element class just using an XML file (*.deeclass) and change the properties added by the behavior definition. This is especially useful for mappers to add variations of Game Objects without needing to touch script code for such a simple task.
Furthermore Element Stubs used to create Game Objects in your game world use the same names as the element class properties. This allows mappers to modify behaviors on a per Game Object basis if required.
You can query BehaviorElementClass if it contains behaviors of a specific type. Some behavior definitions can be used more than once on the same element class. In this case you can assign each instance a unique identifier. This identifier is used to distinguish between the behavior definition instances and acts also as prefix modified of the added element class properties.
Once a BehaviorElement instance is created each behavior definitions adds a subclass of ECBehaviorInstance. These provide the actual behavior to the BehaviorElement instance. Here too you can query the element if it contains instances of a specific behavior.
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.
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, is animated, has two lights, has a speaker and moves along a rail. Basically this describes a kind of train running on a rail between two destinations.
pin Dragengine.Gui
pin Dragengine.Scenery
pin Dragengine.Utils
class MyTrainClass extends BehaviorElementClass
public var ECBehaviorComponent component // visual appearance
public var ECBehaviorAnimated animated // animated the visual appearance
public var ECBehaviorCollider collider // physical interaction
public var ECBehaviorMoveOnRail moveOnRail // move the collider on along a rail
public var ECBehaviorLight headLightLeft // left head light
public var ECBehaviorLight headLightRight // right head light
public var ECBehaviorSpeaker speaker // engine sound
public func new() super("MyTrainTest")
// create visual appearance with default model(mesh), skin and rig. the rig is used both for
// physical interaction and animation purpose. this method assigns the resources located
// in the common directory "/content/train"
component.setCommonPath("/content/train", "train.demodel", "train.deskin", "train.derig")
// create collider which is used for physical interaction. in most situations you want to
// animate the component with the rig. this requires to component behavior to go first
collider = ECBehaviorCollider.new(this, component)
// create head lights. attached to collider with id "headlightLeft" respectively "headlightRight"
headLightLeft = ECBehaviorLight.new(this, collider, "headlightLeft")
headLightLeft.getLight().getColor().setColor(Color.yellow)
headLightLeft.getAttach().getPosition().setVector(Vector.new(-1, 0.5, 2))
headLightRight = ECBehaviorLight.new(this, collider, "headlightRight")
headLightRight.getLight().getColor().setColor(Color.yellow)
headLightRight.getAttach().getPosition().setVector(Vector.new(1, 0.5, 2))
// create engine speaker. attached to the collider
speaker = ECBehaviorSpeaker.new(this, collider)
speaker.getSpeaker().getSound().setPath("/content/train/engine.ogg")
speaker.getAttach().getPosition().setVector(Vector.new(0.0, 0.5, 1.5))
// create behavior animating the visual appearance (component) using an animator
animated = ECBehaviorAnimated.new(this, component)
animated.getAnimator().getAnimator().setPath("/content/train/train.deanimator")
// create behavior moving collider on rail. the mapper defines what rail to use.
// if you assign also the trigger table from the BaseGameApp then the mapper
// can use triggers to start/stop moving the train. if you want to control this
// on your own (or by other behaviors only) leave out this argument
moveOnRail = ECBehaviorMoveOnRail.new(this, collider, BaseGameApp.getApp().getTriggerTable())
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:
class MyTrainClass extends BehaviorElementClass
...
protected func Element createElement()
return MyTrain.new(this)
end
end
class MyTrain extends BehaviorElement
public func new(MyTrainClass eclass) super(eclass)
...
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.
XML Element Classes
XML Element classes allow to create new element classes using an XML file (*.deeclass) instead of writing script code. XML element classes always subclass from an existing script class or XML element class. Using an XML element class you can change properties added by the behavior definitions.
Scripted element classes can be also assigned a list of Behavior Factories. This allows the user to add behaviors to XML element classes if they are in the list of allowed behavior factories. The DragonScript module provides the GenericBehaviorElementClass which contains the factories of all DragonScript module provided behavior factories. You can create your own behaviors and make them available to the generic behavior element class by extending BaseGameApp.createAndAddBehaviorFactories().
Set named element property to string type value. Tag content is string value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
empty string
float
Set named element property to float type value. Tag content is float value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
0
integer
Set named element property to integer type value. Tag content is integer value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
0
boolean
Set named element property to boolean type value. Tag content is boolean value where true, yes, 1 are true values and false, no, 0 are false values. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
false
vector
Set named element property to floating point vector type value. Attributes:
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 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
vector2
Set named element property to floating point vector2 type value. Attributes:
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 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point
Set named element property to integer point type value. Attributes:
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 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point3
Set named element property to integer point3 type value. Attributes:
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 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
borderSize
Set named element property to integer borderSize type value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
left: Left value. Optional. Defaults to 0.
top: Top value. Optional. Defaults to 0.
right: Right value. Optional. Defaults to 0.
bottom: Bottom value. Optional. Defaults to 0.
all: Set left, top, right and bottom to the same value. Optional. Convenience attribute.
0..N
-
rectArea
Set named element property to integer rectArea type value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
floatRectArea
Set named element property to floating point rectArea type value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
color
Set named element property to floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes:
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 0.
g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to 1.
hex: Set color using hex notation. Value can be #rrggbb or #rrggbbaa with components in the range from 00 to ff. Both upper and lower case are valid. Optional. Convenience attribute.
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.
0..N
-
null
Set named element property to null value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
-
list
Set named element property to Array value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
-
map
Set named element property to Dictionary value. Attributes:
name: Name of the property to set. Same name as used for stub properties in world editor. Required.
0..N
-
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
Set named element property to string type value. Tag content is string value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
empty string
float
Set named element property to float type value. Tag content is float value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
0
integer
Set named element property to integer type value. Tag content is integer value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
0
boolean
Set named element property to boolean type value. Tag content is boolean value where true, yes, 1 are true values and false, no, 0 are false values. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
false
vector
Set named element property to floating point vector type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
vector2
Set named element property to floating point vector2 type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point
Set named element property to integer point type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point3
Set named element property to integer point3 type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
borderSize
Set named element property to integer borderSize type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
left: Left value. Optional. Defaults to 0.
top: Top value. Optional. Defaults to 0.
right: Right value. Optional. Defaults to 0.
bottom: Bottom value. Optional. Defaults to 0.
all: Set left, top, right and bottom to the same value. Optional. Convenience attribute.
0..N
-
rectArea
Set named element property to integer rectArea type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
floatRectArea
Set named element property to floating point rectArea type value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
color
Set named element property to floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to 1.
hex: Set color using hex notation. Value can be #rrggbb or #rrggbbaa with components in the range from 00 to ff. Both upper and lower case are valid. Optional. Convenience attribute.
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.
0..N
-
null
Set named element property to null value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
-
list
Set named element property to Array value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
-
map
Set named element property to Dictionary value. Attributes:
name: Name of the parameter/property to set. If the name begins with with . the element property is set using name with behavior property prefix prepended. Otherwise construction parameter is set with the given name. Required.
0..N
-
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 true, yes, 1 are true values and false, no, 0 are false values.
0..N
false
vector
Floating point vector type value. Attributes:
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
vector2
Floating point vector2 type value. Attributes:
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point
Integer point type value. Attributes:
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point3
Integer point3 type value. Attributes:
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
borderSize
Integer borderSize type value. Attributes:
left: Left value. Optional. Defaults to 0.
top: Top value. Optional. Defaults to 0.
right: Right value. Optional. Defaults to 0.
bottom: Bottom value. Optional. Defaults to 0.
all: Set left, top, right and bottom to the same value. Optional. Convenience attribute.
0..N
-
rectArea
Integer rectArea type value. Attributes:
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
floatRectArea
Floating point rectArea type value. Attributes:
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
color
Floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes:
r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to 1.
hex: Set color using hex notation. Value can be #rrggbb or #rrggbbaa with components in the range from 00 to ff. Both upper and lower case are valid. Optional. Convenience attribute.
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.
0..N
-
null
Null value.
0..N
-
list
Array value.
0..N
-
map
Dictionary value.
0..N
-
map
Tag
Description
Occurance
Default
string
Set string value. Attributes:
key: Key to assign value to. Required.
0..N
empty string
float
Set float type value. Tag content is float value. Attributes:
key: Key to assign value to. Required.
0..N
0
integer
Set integer type value. Tag content is integer value. Attributes:
key: Key to assign value to. Required.
0..N
0
boolean
Set boolean type value. Tag content is boolean value where true, yes, 1 are true values and false, no, 0 are false values. Attributes:
key: Key to assign value to. Required.
0..N
false
vector
Set floating point vector type value. Attributes:
key: Key to assign value to. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
vector2
Set floating point vector2 type value. Attributes:
key: Key to assign value to. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point
Set integer point type value. Attributes:
key: Key to assign value to. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
0..N
-
point3
Set integer point3 type value. Attributes:
key: Key to assign value to. Required.
x: X coordinate of vector. Optional. Defaults to 0.
y: Y coordinate of vector. Optional. Defaults to 0.
z: Z coordinate of vector. Optional. Defaults to 0.
0..N
-
borderSize
Set integer borderSize type value. Attributes:
key: Key to assign value to. Required.
left: Left value. Optional. Defaults to 0.
top: Top value. Optional. Defaults to 0.
right: Right value. Optional. Defaults to 0.
bottom: Bottom value. Optional. Defaults to 0.
all: Set left, top, right and bottom to the same value. Optional. Convenience attribute.
0..N
-
rectArea
Set integer rectArea type value. Attributes:
key: Key to assign value to. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
floatRectArea
Set floating point rectArea type value. Attributes:
key: Key to assign value to. Required.
x1: Left value. Optional. Defaults to 0.
y1: Top value. Optional. Defaults to 0.
x2: Right value. Optional. Defaults to 0.
y2: Bottom value. Optional. Defaults to 0.
0..N
-
color
Set floating point color4 type value. Color can be defined either using hex, r/g/b/a or ir/ig/ib/ia. Mixing is not possible. Attributes:
key: Key to assign value to. Required.
r: Red value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
g: Green value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
b: Blue value in the range 0..1 with values outside range allowed. Optional. Defaults to 0.
a: Alpha value in the range 0..1 with values outside range allowed. Optional. Defaults to 1.
hex: Set color using hex notation. Value can be #rrggbb or #rrggbbaa with components in the range from 00 to ff. Both upper and lower case are valid. Optional. Convenience attribute.
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.
0..N
-
null
Set null value. Attributes:
key: Key to assign value to. Required.
0..N
-
list
Set Array value. Attributes:
key: Key to assign value to. Required.
0..N
-
map
Set Dictionary value. Attributes:
key: Key to assign value to. Required.
0..N
-
You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_elements.1741626045.txt.gz · Last modified: 2025/03/10 17:00 by dragonlord