Drag[en]gine Script Module DragonScript  1.23
Dragengine.Scenery.ECBehaviorPlaySound Class Reference

Behavior element behavior play sound using one shot speaker. More...

Inheritance diagram for Dragengine.Scenery.ECBehaviorPlaySound:
Dragengine.Scenery.DefaultECBehavior Dragengine.Scenery.ECBehavior Dragengine.Scenery.BehaviorCompatiblePersistency Dragengine.Scenery.ECBehaviorPlaySoundRandom

Classes

class  Instance
 Behavior instance. More...
 

Public Member Functions

void dispose ()
 Dispose of behavior. More...
 
ECPString getBone ()
 Name of bone to use to null if not used. More...
 
ECBehaviorCollider getCollider ()
 Collider behavior or null if not used. More...
 
ECBehaviorComponent getComponent ()
 Component behavior or null if not used. More...
 
ECPFloat getDistanceOffset ()
 Distance offset for attenuation calculation. More...
 
LayerMask getLayerMask ()
 Layer mask. More...
 
ECPVector getOrientation ()
 Orientation relative to element. More...
 
ECPFloat getPlaySpeed ()
 Play speed. More...
 
ECPVector getPosition ()
 Position relative to element. More...
 
String getPrefix ()
 Prefix. More...
 
ECPFloat getRange ()
 Speaker range. More...
 
ECPFloat getRollOff ()
 Half volume distance. More...
 
ECPSound getSound ()
 Speaker sound. More...
 
ECPEnumeration getSpeakerType ()
 Speaker type. More...
 
ECBehaviorTriggered getTrigger ()
 Trigger play sound. More...
 
TSTriggerTable getTriggerTable ()
 Trigger table or null if not used. More...
 
ECPFloat getVolume ()
 Speaker volume. More...
 
Instance instance (BehaviorElement element)
 Get instance in element from owner element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider)
 Create behavior element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, String id)
 Create behavior element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, String id, String prefix)
 Create behavior element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, TSTriggerTable triggerTable)
 Create behavior element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, TSTriggerTable triggerTable, String id)
 Create behavior element class. More...
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, TSTriggerTable triggerTable, String id, String subID)
 
ECBehaviorPlaySound new (BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider, TSTriggerTable triggerTable, String id, String subID, String prefix)
 
void set (String sound, float range, float volume)
 Set to point speaker with parameters. More...
 
void set (String sound, float range, float volume, Vector position)
 
void set (String sound, float range, float volume, Vector position, Vector orientation)
 
void set (String sound, float range, float volume, Vector position, Vector orientation, String bone)
 
void setLayerMask (LayerMask layerMask)
 Set layer mask. More...
 
- Public Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
void assignInstanceIndex (int instanceIndex)
 Assign instance index. More...
 
String getBehaviorID ()
 Unique identifier of behavior. More...
 
String getID ()
 Identifier. More...
 
int getInstanceIndex ()
 Instance index. More...
 
void loadSupportedData (String identifier, PersistencyEnvironment env, FileReader reader, ECBehaviorInstance instance)
 Load instance data of another behavior. More...
 
bool supportsBehaviorID (String identifier)
 Behavior supports loading instance data of another behavior. More...
 
- Public Member Functions inherited from Dragengine.Scenery.ECBehavior
ECBehaviorInstance createInstance (BehaviorElement element)
 Create Behavior instance. More...
 

Static Public Member Functions

static ECBehaviorPlaySound getBehaviorIn (BehaviorElementClass eclass)
 Get behavior in element class or null if absent. More...
 

Protected Member Functions

void setTriggerTable (TSTriggerTable triggerTable)
 Set trigger table or null if not used. More...
 
- Protected Member Functions inherited from Dragengine.Scenery.DefaultECBehavior
DefaultECBehavior new (BehaviorElementClass eclass)
 Create default composeable behavior with empty identifier. More...
 
DefaultECBehavior new (BehaviorElementClass eclass, String id)
 Create default composeable behavior. More...
 
void setBehaviorID (String identifier)
 Set behavior identifier. More...
 
void useClassNameAsBehaviorID ()
 Set behavior identifier to "<class-name>:<identifier>". More...
 
void useFullyQualifiedClassNameAsBehaviorID ()
 Set behavior identifier to "<fully-qualified-class-name>:<identifier>". More...
 

Detailed Description

Behavior element behavior play sound using one shot speaker.

Behavior is comparable to ECBehaviorSpeaker but does not add a permanent speaker to the element. Instead GWBehaviorOneShotSpeaker.addSpeaker() is used to play a short sound event. One shot speakers are constructed the same way as ECBehaviorSpeaker does. Once deployed the one shot speaker stays in place and vanishes once it finished playing. This is the preferred way to play short sound events like a door lock toggling or firing gun shots.

This behavior can be added multiple times to an element. This allows to play different sound events. Each instance has an identifier which can be used to retrieve a specific instance to play a one shot speaker. The prefix of the speaker class properties is "playSound." . If the identifier is not empty the speaker element class properties have the prefix "{id}.playSound." . This can be overwritten if required.

Hence to use more than one speaker use code like this in your subclass constructor:

class MyElementClass extends BehaviorElementClass
public func new()
ECBehaviorPlaySound.new(this, null, null)
ECBehaviorPlaySound.new(this, null, null, "subPlaySound")
end
end
ECBehaviorPlaySound new(BehaviorElementClass eclass, ECBehaviorComponent component, ECBehaviorCollider collider)
Create behavior element class.

You can now define the parameters to use for both speakers using for example the properties "volume" for the first speaker and "subPlaySound.volume" for the second speaker.

It is recommended to always specify an identifier even if only one speaker is used. This avoids potentially name conflicts especially if other behaviors are added attaching other resources too.

Typical parameters can be set quickly using ECBehaviorPlaySound.set() methods. This is an example of door element class playing a sound for opening and a sound for closing. Both sounds have a range of 30m and play at a volume of 0.8 and play at the center of the door. In XML element classes these sound parameters can be modified using "playSound.open.*" and "playSound.close.*".

Element class properties have the prefix "playSound{(id)}.".

class DoorClass extends BehaviorElementClass
public ECBehaviorPlaySound playSoundOpen
public ECBehaviorPlaySound playSoundClose
public func new()
// create and add play sound behavior for open door sound
playSoundOpen = ECBehaviorPlaySound.new(this, null, null, "open")
playSoundOpen.set("/content/door/open.ogg", 30.0, 0.8, Vector.new(0, 1, 0))
// create and add play sound behavior for close door sound
playSoundClose = ECBehaviorPlaySound.new(this, null, null, "close")
playSoundClose.set("/content/door/close.ogg", 30.0, 0.8, Vector.new(0, 1, 0))
end
end
class Door extends BehaviorElement
public ECBehaviorPlaySound.Instance playSoundOpen
public ECBehaviorPlaySound.Instance playSoundClose
public func new(DoorClass eclass) super(eclass)
// find and store the behavior instances. it is not necessary to store them away
// but doing so is faster especially if playing sound many times and quickly
playSoundOpen = ECBehaviorPlaySound.getInstanceIn(this, null, null, "open")
playSoundClose = ECBehaviorPlaySound.getInstanceIn(this, null, null, "close")
end
public func void openDoor()
// do what is needed to open the door
playSoundOpen.play()
end
public func void closeDoor()
// do what is needed to close the door
playSoundClose.play()
end
end
void set(String sound, float range, float volume)
Set to point speaker with parameters.

If a trigger table is set the trigger expression "triggerPlay" or "{prefix}.triggerPlay" can be used to play sound each time the trigger expression changes and evaluates to true. Using a trigger table is usually only useful if the element can be used by mappers.

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

Member Function Documentation

◆ dispose()

void Dragengine.Scenery.ECBehaviorPlaySound.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

◆ getBehaviorIn()

static ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.getBehaviorIn ( BehaviorElementClass  eclass)
static

Get behavior in element class or null if absent.

Use this method to check if a particular BehaviorElementClass contains a behavior of type ECBehaviorCollider.

◆ getBone()

ECPString Dragengine.Scenery.ECBehaviorPlaySound.getBone ( )

Name of bone to use to null if not used.

◆ getCollider()

ECBehaviorCollider Dragengine.Scenery.ECBehaviorPlaySound.getCollider ( )

Collider behavior or null if not used.

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorPlaySound.getComponent ( )

Component behavior or null if not used.

◆ getDistanceOffset()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getDistanceOffset ( )

Distance offset for attenuation calculation.

Version
1.12

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.

◆ getLayerMask()

LayerMask Dragengine.Scenery.ECBehaviorPlaySound.getLayerMask ( )

Layer mask.

◆ getOrientation()

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.getOrientation ( )

Orientation relative to element.

◆ getPlaySpeed()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getPlaySpeed ( )

Play speed.

◆ getPosition()

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.getPosition ( )

Position relative to element.

◆ getPrefix()

String Dragengine.Scenery.ECBehaviorPlaySound.getPrefix ( )

Prefix.

◆ getRange()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getRange ( )

Speaker range.

◆ getRollOff()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getRollOff ( )

Half volume distance.

◆ getSound()

ECPSound Dragengine.Scenery.ECBehaviorPlaySound.getSound ( )

Speaker sound.

◆ getSpeakerType()

ECPEnumeration Dragengine.Scenery.ECBehaviorPlaySound.getSpeakerType ( )

Speaker type.

◆ getTrigger()

ECBehaviorTriggered Dragengine.Scenery.ECBehaviorPlaySound.getTrigger ( )

Trigger play sound.

◆ getTriggerTable()

TSTriggerTable Dragengine.Scenery.ECBehaviorPlaySound.getTriggerTable ( )

Trigger table or null if not used.

◆ getVolume()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getVolume ( )

Speaker volume.

◆ instance()

Instance Dragengine.Scenery.ECBehaviorPlaySound.instance ( BehaviorElement  element)

Get instance in element from owner element class.

◆ new() [1/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider 
)

Create behavior element class.

These values are optional and can be null: component, collider.

Reimplemented in Dragengine.Scenery.ECBehaviorPlaySoundRandom.

◆ new() [2/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
String  id 
)

Create behavior element class.

Reimplemented in Dragengine.Scenery.ECBehaviorPlaySoundRandom.

◆ new() [3/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
String  id,
String  prefix 
)

Create behavior element class.

Reimplemented in Dragengine.Scenery.ECBehaviorPlaySoundRandom.

◆ new() [4/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
TSTriggerTable  triggerTable 
)

Create behavior element class.

Reimplemented in Dragengine.Scenery.ECBehaviorPlaySoundRandom.

◆ new() [5/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
TSTriggerTable  triggerTable,
String  id 
)

Create behavior element class.

Reimplemented in Dragengine.Scenery.ECBehaviorPlaySoundRandom.

◆ new() [6/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
TSTriggerTable  triggerTable,
String  id,
String  subID 
)

◆ new() [7/7]

ECBehaviorPlaySound Dragengine.Scenery.ECBehaviorPlaySound.new ( BehaviorElementClass  eclass,
ECBehaviorComponent  component,
ECBehaviorCollider  collider,
TSTriggerTable  triggerTable,
String  id,
String  subID,
String  prefix 
)

◆ set() [1/4]

void Dragengine.Scenery.ECBehaviorPlaySound.set ( String  sound,
float  range,
float  volume 
)

Set to point speaker with parameters.

Helper method to quickly set up playing sound.

◆ set() [2/4]

void Dragengine.Scenery.ECBehaviorPlaySound.set ( String  sound,
float  range,
float  volume,
Vector  position 
)

◆ set() [3/4]

void Dragengine.Scenery.ECBehaviorPlaySound.set ( String  sound,
float  range,
float  volume,
Vector  position,
Vector  orientation 
)

◆ set() [4/4]

void Dragengine.Scenery.ECBehaviorPlaySound.set ( String  sound,
float  range,
float  volume,
Vector  position,
Vector  orientation,
String  bone 
)

◆ setLayerMask()

void Dragengine.Scenery.ECBehaviorPlaySound.setLayerMask ( LayerMask  layerMask)

Set layer mask.

◆ setTriggerTable()

void Dragengine.Scenery.ECBehaviorPlaySound.setTriggerTable ( TSTriggerTable  triggerTable)
protected

Set trigger table or null if not used.


The documentation for this class was generated from the following file: