User Tools

Site Tools


dragengine:modules:dragonscript:behavior_elements

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
dragengine:modules:dragonscript:behavior_elements [2025/03/10 17:23] – [Examples] dragonlorddragengine:modules:dragonscript:behavior_elements [2025/03/26 11:45] (current) – [Examples] dragonlord
Line 35: Line 35:
 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. 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.
  
 +++++ Show Example|
 <code> <code>
 pin Dragengine.Gui pin Dragengine.Gui
Line 85: Line 86:
 end end
 </code> </code>
 +++++
  
 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|
 <code> <code>
 class MyTrainClass extends BehaviorElementClass class MyTrainClass extends BehaviorElementClass
Line 102: Line 105:
 end end
 </code> </code>
 +++++
  
 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.
  
 +====== Attachable Behaviors ======
 +
 +Attachable behaviors allow to add temporary behaviors to an element at runtime. They are similar in how the work to regular behaviors but instead of being added to #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# they are added to #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# directly. Hence while all #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElement.html,BehaviorElement~@# belonging to the same #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1BehaviorElementClass.html,BehaviorElementClass~@# own the same behaviors they all can have individual attachable behaviors. Furthermore attachable behaviors can be removed which can not be done with regular behaviors.
 +
 +Attachable behaviors implement #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ECAttachableBehavior.html,ECAttachableBehavior~@# or subclass #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1DefaultECAttachableBehavior.html,DefaultECAttachableBehavior~@#. At runtime script code can attach behaviors using BehaviorElement.addAttachableBehavior() as well as removing it any time using BehaviorElement.removeAttachableBehavior().
 +
 +Once added attachable behaviors can react to similar events like behaviors if they request it. Usually attachable behaviors react to onAddToElement() and onRemoveFromElement() to add or remove their effect to the parent element. 
 +
 +Attachable behaviors also are required to be persistable the same way as behaviors are. Hence attachable behaviors added to behavior elements are persisted in a future proof way as regular behaviors are.
 +
 +Important to note is that attachable behaviors do not use the same interface as regular behaviors. This is on purpose since regular behaviors are split into ECBehavior and ECBehaviorInstance working together while ECAttachableBehavior is a standalone instance.
 ====== XML Element Classes ====== ====== XML Element Classes ======
 +
 +<WRAP center 100%>
 +<WRAP center box 1050px>
 +{{ youtube>heBLyt3b6G0?1000x591 }}
 +<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.</WRAP>
 +</WRAP>
 +</WRAP>
  
 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. 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.
Line 519: Line 542:
 This example creates a simple XML element class based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1SimpleElementClass.html,SimpleElementClass~@#. It modifies some element properties to use a specific model, skin and rig resource. The path are either absolute path (if starting with ''/'') or relative to the directory the ''*.deeclass'' file is located in. This example creates a simple XML element class based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1SimpleElementClass.html,SimpleElementClass~@#. It modifies some element properties to use a specific model, skin and rig resource. The path are either absolute path (if starting with ''/'') or relative to the directory the ''*.deeclass'' file is located in.
  
 +++++ Show Example|
 <code xml> <code xml>
 <?xml version='1.0' encoding='UTF-8'?> <?xml version='1.0' encoding='UTF-8'?>
Line 529: Line 553:
 </elementClass> </elementClass>
 </code> </code>
 +++++
  
 This example creates a complex XML element class which is based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1GenericBehaviorElementClass.html,GenericBehaviorElementClass~@#. This allows adding behaviors inside the ''*.deeclass'' file avoiding the need to write an explicit script class to do the same. This is the example file used in the behavior factory video above. This example creates a complex XML element class which is based on the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1GenericBehaviorElementClass.html,GenericBehaviorElementClass~@#. This allows adding behaviors inside the ''*.deeclass'' file avoiding the need to write an explicit script class to do the same. This is the example file used in the behavior factory video above.
  
 +++++ Show Example|
 <code xml> <code xml>
 <?xml version='1.0' encoding='ISO-8859-1'?> <?xml version='1.0' encoding='ISO-8859-1'?>
Line 744: Line 770:
 </elementClass> </elementClass>
 </code> </code>
 +++++
  
dragengine/modules/dragonscript/behavior_elements.1741627399.txt.gz · Last modified: 2025/03/10 17:23 by dragonlord