Start Page » DragonScript Scripting Language » Abstraction Layers: How you want to build your Game » Behavior Elements » ECBehaviorTouching
Behavior element behavior matching trigger target to touching sensor.
Fires and resets a trigger target depending if elements are in touch sensor. Optionally pulses trigger target instead of just firing it.
This behavior can be used multiple times on an element to add multiple triggers. Use the behavior identifier to tell them apart.
Element class properties have the prefix touching.
or touching({id}).
if id is not empty.
Behavior adds a child ECBehaviorTouchSensor. The child behavior has the identifier touchSensor
or touchSensor({id})
. The properties of the child behavior have the prefix touching.touchSensor.
or touching({id}).touchSensor.
<string name='touching.touchSensor.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>
Fires target if one or more elements touch the child touch sensor. Resets target as soon as no element touches the child touch sensor anymore.
touching.target
or touching({id}).target
<string name='touching.target'>playerEntered</string>
Pulse target instead of toggle fired state. Hence the first time an element touches the child touch sensor the target is pulsed. Nothing happens until the last element stops touching the child touch sensor. At that time the trigger is ready again to fire if an element touches the child touch sensor.
touching.pulse
or touching({id}).pulse
false
<boolean name='touching.pulse'>true</boolean>
First element entered touch sensor.
Last element left touch sensor.
This behavior requires no other behaviors.
This behavior does not required element class to be persistable (setPersistable).
Since DragonScript Module Version 1.0
This example defines an element which fire target on elements touching.
class MyElement extends BehaviorElementClass public var ECBehaviorComponent component public var ECBehaviorCollider collider public var ECBehaviorTouching touching func new() component = ECBehaviorComponent.new(this, null) collider = ECBehaviorCollider.new(this, component) touching = ECBehaviorTouching.new(this, collider) 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'> <behavior type='ECBehaviorComponent'/> <behavior type='ECBehaviorCollider'/> <behavior type='ECBehaviorTouching'> <!-- set element properties. omit property prefix if used inside behavior tag --> <string name='.target'>playerEntered</string> </behavior> <!-- for adding multiple behaviors use unique identifiers --> <behavior type='ECBehaviorTouching' id='second'/> </elementClass>