Skip to content

SgAudioListener

Represents the audio listener in the scene, typically attached to the camera or player. It determines how positional audio is perceived based on its location and orientation. Only one SgAudioListener should be active at a time to ensure correct spatial audio playback.

Inherits from

SceneObject

Usage

To use this class, add the following require at the top of your script:

local SgAudioListener = require 'engine/sceneobjects/sgaudiolistener'

Reference

create

static create(self, options, parent)

Create a new audio listener object in the scenegraph.

Parameters

  • self
  • options (table): A table of options to fill the parameters
  • parent (SceneObject): The parent scene object to add this to

Returns

  • Promise: promise which will resolve to the created object

Example

-- Options can be omitted. This example shows the defaults,
-- only specify the ones you want different.
SgAudioListener.create({
    active = true,
    name = "",
    transform = Transform.new(),
    tags = {},
    gain = 1,
    timeDelta = 1
})

Properties

You can access these properties directly on the object or through :get("propertyName") or :set("propertyName", value) methods.

Property Type Default Description
active Boolean true Whether this listener receives spatial audio. Typically only one should be active.
transform Transform Transform.new() Position and orientation used for 3D audio panning and attenuation.
tags Tags [] Labels attached to this listener for scripting.
gain Float 1 Master gain applied to all audio heard through this listener.
timeDelta Float 1 Elapsed time since the last audio update, used internally for smoothing.