Skip to content

Class: sound_object ​

Play an engine sound resource from scripts.

Source ​

C++ class sound_object

Custom Constructor ​

sound_object

Remarks ​

Most playback and parameter APIs require the sound resource to exist, unless the engine is running with sound disabled. Missing files are logged at construction and fail later when playback starts.

Constructors ​

Constructor ​

ts
new sound_object(sound_path: string): sound_object;

Create a sound from $game_sounds$/<sound_path>.ogg.

Parameters ​

ParameterTypeDescription
sound_pathstringSound resource path without extension.

Returns ​

sound_object

Remarks ​

Missing sound files are logged during construction. Playback methods will throw later if the sound handle was not created.

Constructor ​

ts
new sound_object(sound_path: string, type: TXR_snd_type): sound_object;

Create a typed sound from $game_sounds$/<sound_path>.ogg.

Parameters ​

ParameterTypeDescription
sound_pathstringSound resource path without extension.
typeTXR_snd_typeSound category used by AI sound memory.

Returns ​

sound_object

Remarks ​

Missing sound files are logged during construction. Playback methods will throw later if the sound handle was not created.

Methods ​

attach_tail() ​

ts
attach_tail(sound_path: string): void;

Append a tail sound played after this sound ends.

Parameters ​

ParameterTypeDescription
sound_pathstringSound resource path without extension.

Returns ​

void

Remarks ​

The tail path is passed to the engine sound handle as-is. Use a game sound resource path without extension.


get_position() ​

ts
get_position(): vector;

Get the current playback position.

Returns ​

vector

Current sound position.

Remarks ​

Logs an engine script error and returns a zero vector if the sound was not launched.


length() ​

ts
length(): number;

Get sound length in milliseconds.

Returns ​

number

Sound duration.

Remarks ​

Reads the engine sound handle. Do not use it as a file-existence check after construction logged a missing file.


play() ​

Call Signature ​

ts
play(object: Nillable<game_object>): void;

Play the sound attached to an object, or globally when object is null.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Object used as sound owner.
Returns ​

void

Throws ​

If the sound handle was not created.

Call Signature ​

ts
play(object: Nillable<game_object>, delay: number): void;

Play the sound after a delay.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Object used as sound owner.
delaynumberDelay in seconds.
Returns ​

void

Throws ​

If the sound handle was not created.

Call Signature ​

ts
play(
   object: Nillable<game_object>, 
   delay: number, 
   flags: number): void;

Play the sound with engine sound flags.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Object used as sound owner.
delaynumberDelay in seconds.
flagsnumberPlayback flags such as sound_object.looped or sound_object.s2d.
Returns ​

void

Throws ​

If the sound handle was not created.


play_at_pos() ​

Call Signature ​

ts
play_at_pos(object: Nillable<game_object>, position: vector): void;

Play the sound at a fixed world position.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Optional object used as sound owner.
positionvectorWorld position for playback.
Returns ​

void

Throws ​

If the sound handle was not created.

Call Signature ​

ts
play_at_pos(
   object: Nillable<game_object>, 
   position: vector, 
   delay: number): void;

Play the sound at a fixed world position after a delay.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Optional object used as sound owner.
positionvectorWorld position for playback.
delaynumberDelay in seconds.
Returns ​

void

Throws ​

If the sound handle was not created.

Call Signature ​

ts
play_at_pos(
   object: Nillable<game_object>, 
   position: vector, 
   delay: number, 
   flags: number): void;

Play the sound at a fixed world position with engine sound flags.

Parameters ​
ParameterTypeDescription
objectNillable<game_object>Optional object used as sound owner.
positionvectorWorld position for playback.
delaynumberDelay in seconds.
flagsnumberPlayback flags such as sound_object.looped or sound_object.s2d.
Returns ​

void

Throws ​

If the sound handle was not created.


play_no_feedback() ​

ts
play_no_feedback(
   object: Nillable<game_object>, 
   flags: number, 
   delay: number, 
   position: vector, 
   volume: number): void;

Play without tracking feedback.

Parameters ​

ParameterTypeDescription
objectNillable<game_object>Optional object used as sound owner.
flagsnumberPlayback flags.
delaynumberDelay in seconds.
positionvectorOptional playback position.
volumenumberOptional playback volume.

Returns ​

void

Remarks ​

This starts playback without storing feedback on the sound_object, so playing() will not describe this playback instance.

Throws ​

If the sound handle was not created.


playing() ​

ts
playing(): boolean;

Check whether the sound has active playback feedback.

Returns ​

boolean

Whether the sound is currently playing.

Remarks ​

Sounds started with play_no_feedback are intentionally not tracked by feedback.


set_position() ​

ts
set_position(position: vector): void;

Move the sound emitter.

Parameters ​

ParameterTypeDescription
positionvectorNew world position.

Returns ​

void

Throws ​

If the sound handle was not created.


stop() ​

ts
stop(): void;

Stop playback immediately.

Returns ​

void

Throws ​

If the sound handle was not created.


stop_deferred() ​

ts
stop_deferred(): void;

Stop playback through the engine deferred-stop path.

Returns ​

void

Remarks ​

Preferred spelling. stop_deffered is kept for script compatibility.

Throws ​

If the sound handle was not created.


stop_deffered() ​

ts
stop_deffered(): void;

Stop playback through the engine deferred-stop path.

Returns ​

void

Remarks ​

Legacy misspelled alias for stop_deferred.

Throws ​

If the sound handle was not created.

Properties ​

frequency ​

ts
frequency: number;

Playback frequency multiplier.


max_distance ​

ts
max_distance: number;

Maximum audible distance in meters.


min_distance ​

ts
min_distance: number;

Minimum distance before attenuation starts.


volume ​

ts
volume: number;

Playback volume.


looped ​

ts
readonly static looped: 1;

Keep playing until stopped.


s2d ​

ts
readonly static s2d: 2;

Screen-space 2D playback.


s3d ​

ts
readonly static s3d: 0;

Spatial 3D playback.