// 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()
class SceneAudioPlayer
SceneAudioPlayer
(
scene
, soundAsset
)
|
Creates a new audio player for the specified audio asset.
Signature
constructor(scene: Scene, soundAsset: SceneAudioAsset) Parameters Returns |
play
(
position
, volume
, looping
)
|
Starts playing the audio at the specified position.
Signature
fun play(position: Vector3, volume: Float = 1.0f, looping: Boolean = false) Parameters
volume:
Float
looping:
Boolean
|
setPosition
(
position
)
|
Updates the position of the currently playing audio.
This can be used to move the sound source while it's playing, for example to follow a moving object in the scene.
Signature
fun setPosition(position: Vector3) Parameters |
setVolume
(
volume
)
|
Adjusts the volume of the currently playing audio.
Signature
fun setVolume(volume: Float) Parameters
volume:
Float
|
stop
()
|
Stops the audio playback.
Once stopped, the audio can be played again by calling SceneAudioPlayer.play.
Signature
fun stop() |
playerCount
: Int
[Get] |
Signature
var playerCount: Int |