Drag[en]gine Script Module DragonScript 1.35
Loading...
Searching...
No Matches
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  Factory
 Behavior factory. More...
class  Instance
 Behavior instance. More...

Public Member Functions

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

Static Public Member Functions

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

Public Attributes

ECBehaviorBehaviorTree pBehaviorTree
ECPString pBone
ECBehaviorCollider pCollider
ECBehaviorComponent pComponent
ECPFloat pDistanceOffset
ECPLayerMask pLayerMask
ECPVector pOrientation
ECPFloat pPlaySpeed
ECPVector pPosition
String pPrefix
ECPFloat pRange
ECPFloat pRollOff
ECPSound pSound
ECPEnumeration pSpeakerType
ECBehaviorTriggered pTrigger
TSTriggerTable pTriggerTable
ECPFloat pVolume

Protected Member Functions

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

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
func new()
ECBehaviorPlaySound.new(this, null, null)
ECBehaviorPlaySound.new(this, null, null, "subPlaySound")
end
end
Behavior element element class.
Definition BehaviorElementClass.ds:54
Behavior element behavior play sound using one shot speaker.
Definition ECBehaviorPlaySound.ds:124
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
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
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
func void openDoor()
// do what is needed to open the door
playSoundOpen.play()
end
func void closeDoor()
// do what is needed to close the door
playSoundClose.play()
end
end
Behavior element.
Definition BehaviorElement.ds:56
Behavior instance.
Definition ECBehaviorPlaySound.ds:170
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).

See also
https://developer.dragondreams.ch/wiki/doku.php/dragengine:modules:dragonscript:behavior_playsound

Member Function Documentation

◆ dispose()

void Dragengine.Scenery.ECBehaviorPlaySound.dispose ( )

Dispose of behavior.

Reimplemented from Dragengine.Scenery.DefaultECBehavior.

References getRange(), and pRange.

Referenced by getBehaviorIn().

◆ getBehaviorIn()

◆ getBehaviorTree()

ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorPlaySound.getBehaviorTree ( )

Behavior tree or null.

Version
1.26

References getBone(), and pBone.

Referenced by getBehaviorIn(), and Dragengine.Scenery.ECBehaviorPlaySound.Instance.getDistanceOffset().

◆ getBone()

ECPString Dragengine.Scenery.ECBehaviorPlaySound.getBone ( )

Name of bone to use to null if not used.

Referenced by getBehaviorIn(), and getBehaviorTree().

◆ getCollider()

ECBehaviorCollider Dragengine.Scenery.ECBehaviorPlaySound.getCollider ( )

Collider behavior or null if not used.

References pRange.

Referenced by getBehaviorIn().

◆ getComponent()

ECBehaviorComponent Dragengine.Scenery.ECBehaviorPlaySound.getComponent ( )

Component behavior or null if not used.

Referenced by getBehaviorIn(), and instance().

◆ 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.

Referenced by getBehaviorIn(), and getRollOff().

◆ getLayerMask()

LayerMask Dragengine.Scenery.ECBehaviorPlaySound.getLayerMask ( )
Deprecated
Use getLayerMaskProperty() instead.

References pPosition.

Referenced by getBehaviorIn().

◆ getLayerMaskProperty()

ECPLayerMask Dragengine.Scenery.ECBehaviorPlaySound.getLayerMaskProperty ( )

Layer mask property.

Version
1.35

References pPosition.

Referenced by getBehaviorIn().

◆ getOrientation()

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.getOrientation ( )

Orientation relative to element.

References getPlaySpeed(), and pPlaySpeed.

Referenced by getBehaviorIn(), and getTriggerTable().

◆ getPlaySpeed()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getPlaySpeed ( )

Play speed.

Referenced by getBehaviorIn(), and getOrientation().

◆ getPosition()

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.getPosition ( )

Position relative to element.

References pDistanceOffset.

Referenced by getBehaviorIn(), and getTrigger().

◆ getPrefix()

String Dragengine.Scenery.ECBehaviorPlaySound.getPrefix ( )

◆ getRange()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getRange ( )

Speaker range.

Referenced by dispose(), and getBehaviorIn().

◆ getRollOff()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getRollOff ( )

Half volume distance.

References getDistanceOffset(), and pDistanceOffset.

Referenced by getBehaviorIn(), and getPrefix().

◆ getSound()

ECPSound Dragengine.Scenery.ECBehaviorPlaySound.getSound ( )

Speaker sound.

References pRollOff.

Referenced by getBehaviorIn(), and new().

◆ getSpeakerType()

ECPEnumeration Dragengine.Scenery.ECBehaviorPlaySound.getSpeakerType ( )

Speaker type.

Referenced by getBehaviorIn().

◆ getTrigger()

ECBehaviorTriggered Dragengine.Scenery.ECBehaviorPlaySound.getTrigger ( )

Trigger play sound.

References getPosition(), and pPlaySpeed.

Referenced by getBehaviorIn(), and set().

◆ getTriggerTable()

TSTriggerTable Dragengine.Scenery.ECBehaviorPlaySound.getTriggerTable ( )

Trigger table or null if not used.

References getOrientation(), and pOrientation.

Referenced by getBehaviorIn(), and Dragengine.Scenery.ECBehaviorPlaySound.Instance.setRollOff().

◆ getVolume()

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.getVolume ( )

Speaker volume.

Referenced by getBehaviorIn(), and new().

◆ instance()

◆ 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.

References getSound(), and pSound.

Referenced by getBehaviorIn().

◆ 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.

References pSound.

◆ 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.

References getVolume().

◆ 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.

References pVolume.

◆ 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.

Referenced by getBehaviorIn().

◆ set() [2/4]

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

References getTrigger(), and pTrigger.

◆ 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 )

◆ setBehaviorTree()

void Dragengine.Scenery.ECBehaviorPlaySound.setBehaviorTree ( ECBehaviorBehaviorTree behaviorTree)

◆ setLayerMask()

◆ setTriggerTable()

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

Set trigger table or null if not used.

References pOrientation.

Referenced by getBehaviorIn().

Member Data Documentation

◆ pBehaviorTree

ECBehaviorBehaviorTree Dragengine.Scenery.ECBehaviorPlaySound.pBehaviorTree

Referenced by getBehaviorIn().

◆ pBone

ECPString Dragengine.Scenery.ECBehaviorPlaySound.pBone

◆ pCollider

ECBehaviorCollider Dragengine.Scenery.ECBehaviorPlaySound.pCollider

Referenced by getBehaviorIn().

◆ pComponent

ECBehaviorComponent Dragengine.Scenery.ECBehaviorPlaySound.pComponent

Referenced by getBehaviorIn(), and instance().

◆ pDistanceOffset

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.pDistanceOffset

◆ pLayerMask

ECPLayerMask Dragengine.Scenery.ECBehaviorPlaySound.pLayerMask

Referenced by getBehaviorIn().

◆ pOrientation

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.pOrientation

◆ pPlaySpeed

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.pPlaySpeed

◆ pPosition

ECPVector Dragengine.Scenery.ECBehaviorPlaySound.pPosition

◆ pPrefix

String Dragengine.Scenery.ECBehaviorPlaySound.pPrefix

Referenced by getBehaviorIn().

◆ pRange

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.pRange

Referenced by dispose(), getBehaviorIn(), and getCollider().

◆ pRollOff

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.pRollOff

Referenced by getBehaviorIn(), getPrefix(), and getSound().

◆ pSound

ECPSound Dragengine.Scenery.ECBehaviorPlaySound.pSound

Referenced by getBehaviorIn(), new(), and new().

◆ pSpeakerType

ECPEnumeration Dragengine.Scenery.ECBehaviorPlaySound.pSpeakerType

Referenced by getBehaviorIn().

◆ pTrigger

ECBehaviorTriggered Dragengine.Scenery.ECBehaviorPlaySound.pTrigger

Referenced by getBehaviorIn(), and set().

◆ pTriggerTable

TSTriggerTable Dragengine.Scenery.ECBehaviorPlaySound.pTriggerTable

Referenced by getBehaviorIn().

◆ pVolume

ECPFloat Dragengine.Scenery.ECBehaviorPlaySound.pVolume

Referenced by getBehaviorIn(), new(), and new().


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