User Tools

Site Tools


dragengine:modules:dragonscript:behavior_announcer

ECBehaviorAnnouncer

Behavior element behavior adding announcer support.

Behavior uses an Announcer to play back announcer files. The speaker created by the Announcer instance is added to the game world.

If the ECBehaviorCollider is present the announcer speaker is attached. The speaker is attached to the named bone if defined otherwise it is attached statically.

This behavior contains a property to set the announcement text. Other behaviors can change this text at runtime to make this alter the announcement. Changing the announcement text will stop playing back the current announcement.

Instance Counts

This behavior can be added multiple times to an element. Each instance creates one announcer speaker attached to the element collider which can be individually modified. To distinguish the announcers each instance has an identifier which can be used to retrieve a specific instance.

Element Class Properties

Element class properties have the prefix announcer. or announcer({id}). if id is not empty.

path

Path to announcer file to load.

  • Full name: announcer.path or announcer({id}).path
  • Type: string
  • Default Value: empty string
  • Expected File Type: *.announcer.xml
  • Example (*.deeclass)
    <string name='announcer.path'>speaker.announcer.xml</string>

type

Speaker type.

  • Full name: announcer.type or announcer({id}).type
  • Type: enumeration
  • Allowed Values:

    ValueDescription
    pointOmnidirectional.
    directedDirected.
  • Default Value: point
  • Example (*.deeclass)
    <string name='announcer.type'>directed</string>

volume

Speaker volume.

  • Full name: announcer.volume or announcer({id}).volume
  • Type: float
  • Default Value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='announcer.volume'>0.8</float>

range

Speaker range in meters. Speaker is inaudible beyond range.

  • Full name: announcer.range or announcer({id}).range
  • Type: float
  • Default Value: 30
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='announcer.range'>20</float>

rollOff

Roll off. Value 1 is realistic (normal) roll-off. Values larger than 1 reduce volume faster near the sound source. Values smaller than 1 reduce volume faster near the sound range.

  • Full name: announcer.rollOff or announcer({id}).rollOff
  • Type: float
  • Default Value: 1
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='announcer.rollOff'>1.5</float>

distanceOffset

Distance offset for attenuation calculation. For use by distance sounds. Offsets the true distance to the sound source for attenuation calculation to make the sound appear coming from far away. Requires increasing the volume to compensate for the distance increased attenuation.

  • Full name: announcer.distanceOffset or announcer({id}).distanceOffset
  • Type: float
  • Default Value: 0
  • Restriction: At least 0
  • Example (*.deeclass)
    <float name='announcer.distanceOffset'>500</float>

shape

Speaker shape.

  • Full name: announcer.shape or announcer({id}).shape
  • Type: string (shape format). See “Shape List Encoding” in CodecPropertyString.
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='announcer.shape'>box:position,0,0.5,0:extends,2,1,0.5</string>

text

Announcement text.

  • Full name: announcer.text or announcer({id}).text
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='announcer.text'>This is an announcement.</string>

position

Position to attach resource to collider.

  • Full name: announcer.position or announcer({id}).position
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='announcer.position' x='0' y='0' z='0.1'/>

orientation

Orientation to attach resource to collider in degrees.

  • Full name: announcer.orientation or announcer({id}).orientation
  • Type: 3-component float vector
  • Default Value: (0,0,0)
  • Example (*.deeclass)
    <vector name='announcer.orientation' x='30' y='0' z='0'/>

bone

Bone to attach resource to. If empty string attach to collider.

  • Full name: announcer.bone or announcer({id}).bone
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='announcer.bone'>attach</string>

trigger

Play announcement whenever trigger evaluates to true.

  • Full name: announcer.trigger or announcer({id}).trigger
  • Type: string
  • Default Value: empty string
  • Example (*.deeclass)
    <string name='announcer.trigger'>@switchOnVent & @powerEnabled</string>

Events

startAnnouncement

Start playing back announcement.

stopAnnouncement

Stop playing back announcement.

Required Behaviors

This behavior requires no other behaviors.

Optional Behaviors

Persistency

This behavior does not required element class to be persistable (setPersistable).

API Documentation

ECBehaviorAnnouncer.

Since DragonScript Module Version 1.0

Use Cases

  • Play announcement through speaker composed of pre-recorded words.

Element Class Example

This example defines an element which supports playing announcements.

class MyElement extends BehaviorElementClass
  public var ECBehaviorComponent component
  public var ECBehaviorCollider collider
  public var ECBehaviorAnnouncer announcer
  func new()
    component = ECBehaviorComponent.new(this, null)
    collider = ECBehaviorCollider.new(this, component)
    announcer = ECBehaviorAnnouncer.new(this, collider)
  end
end

Behavior Factory

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='ECBehaviorAnnouncer'>
    <!-- optional: set layer mask (default '2' meaning BaseGameApp.WorldLayerBit.audio).
                   list of bits to set. -->
    <string name='layerMask'>0 1 4</string>
 
    <!-- optional: use BaseGameApp trigger table. game can add more supported values -->
    <string name='triggerTable'>default</string>
 
    <!-- set element properties. omit property prefix if used inside behavior tag -->
    <string name='.text'>This is an announcement.</string>
  </behavior>
 
  <!-- for adding multiple behaviors use unique identifiers -->
  <behavior type='ECBehaviorAnnouncer' id='second'/>
</elementClass>

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_announcer.txt · Last modified: 2025/03/13 17:16 by dragonlord