class SceneAudioPlayer
// Load an audio asset
val audioAsset = SceneAudioAsset.loadLocalFile("data/common/audio/ambient.ogg")
// Create an audio player for the asset
val audioPlayer = SceneAudioPlayer(scene, audioAsset)
// Play the sound at a specific position with looping enabled
audioPlayer.play(
position = Vector3(0f, 1.7f, -2f),
volume = 0.8f,
looping = true
)
// Later, update the volume
audioPlayer.setVolume(0.5f)
// Move the sound to follow an object
audioPlayer.setPosition(objectPosition)
// Stop playback when no longer needed
audioPlayer.stop()
| Name | Summary |
|---|---|
SceneAudioPlayer | constructor(scene: Scene, soundAsset: SceneAudioAsset) Creates a new audio player for the specified audio asset. |
| Name | Summary |
|---|---|
Companion | object Companion |
| Name | Summary |
|---|---|
play | fun play(position: Vector3, volume: Float = 1.0f, looping: Boolean = false) Starts playing the audio at the specified position. |
setPosition | |
setVolume | fun setVolume(volume: Float) Adjusts the volume of the currently playing audio. |
stop | fun stop() Stops the audio playback. |
object Companion
| Name | Summary |
|---|---|
playerCount | var playerCount: Int |