core.audio_2d.create

Client

Creates a new audio-2d instance from a file path


Syntax

local instance = core.audio_2d.create(
    path,
    autoplay = false
)

Parameters

TypeNameDescription
stringpathFile path to the audio asset
Refer Formats section
boolautoplayDetermines whether the audio starts playing immediately:
• When true - playback begins as soon as the instance is created
• When false - playback must be started manually via self:play()

Returns

TypeNameDescription
audio_2dinstanceCreated audio-2d instance

Formats

FormatExtensionDescription
OGG.oggLossy compressed audio, ideal for music and ambience
WAV.wavUncompressed audio, no lossy artifacts
MP3.mp3Lossy compressed audio, widely supported format

Examples

Create a basic audio-2d instance
local entity = core.audio_2d.create("sounds/ambient.ogg")

entity:play()
Create an instance that starts playing immediately
local entity = core.audio_2d.create("sounds/ambient.ogg", true)

entity:set_volume(1.0)

On this page