Skip to content

SgAudio

Represents a non-positional audio source in the scene graph. Used to play background music or UI sounds that are not tied to any 3D location. Ideal for ambient tracks or global sound effects.

Inherits from

SceneObject

Usage

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

local SgAudio = require 'engine/sceneobjects/sgaudio'

Reference

create

static create(self, options, parent)

Create a new audio 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.
SgAudio.create({
    active = true,
    name = "",
    transform = Transform.new(),
    layers = {0},
    tags = {},
    autoplay = false,
    loop = false,
    volume = 1,
    panning = 0,
    playbackRate = 1,
    offset = 0
})

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
tags Tags []
sourceType Enum Single Options: Single, Collection
autoplay Boolean false
loop Boolean false
volume Float 1
panning Float 0
duration Float 0
detune Float 0
playbackRate Float 1
offset Float 0