Component that plays audio using the AudioService.
More...
#include <audio_source.h>
Component that plays audio using the AudioService.
AudioSource allows a GameObject to play sounds, with options for looping, volume control, and play-on-awake functionality.
- Parameters
-
| audio_file_path | The file path to the audio clip. |
| play_on_awake | Whether the audio should play automatically when the component is attached. |
| loop | Whether the audio should loop after finishing. |
| volume | The volume level of the audio (0.0 to 1.0). |
Usage:
- Create an AudioSource with the desired audio file and settings.
- Call play() to start playback, and stop() to halt it.
- Adjust volume and looping settings as needed.
- Note
- Ensure the audio file exists and is in a supported format.
◆ AudioSource()
| AudioSource::AudioSource |
( |
std::string |
audio_file_path, |
|
|
bool |
play_on_awake = true, |
|
|
bool |
loop = false, |
|
|
float |
volume = 1.0f |
|
) |
| |
|
explicit |
◆ ~AudioSource()
| AudioSource::~AudioSource |
( |
| ) |
|
|
overridedefault |
◆ audio_file_path() [1/2]
| const std::string & AudioSource::audio_file_path |
( |
| ) |
const |
|
noexcept |
◆ audio_file_path() [2/2]
| void AudioSource::audio_file_path |
( |
const std::string & |
path | ) |
|
|
noexcept |
◆ audio_name()
| std::string AudioSource::audio_name |
( |
| ) |
const |
|
noexcept |
◆ instance()
| std::optional< std::reference_wrapper< SoundInstance > > AudioSource::instance |
( |
| ) |
const |
|
noexcept |
◆ loop() [1/2]
| bool AudioSource::loop |
( |
| ) |
const |
|
noexcept |
◆ loop() [2/2]
| void AudioSource::loop |
( |
bool |
value | ) |
|
|
noexcept |
◆ on_attach()
| void AudioSource::on_attach |
( |
| ) |
|
|
overridevirtual |
◆ on_detach()
| void AudioSource::on_detach |
( |
| ) |
|
|
overridevirtual |
◆ play()
| void AudioSource::play |
( |
bool |
loop = false | ) |
|
◆ play_on_awake() [1/2]
| bool AudioSource::play_on_awake |
( |
| ) |
const |
|
noexcept |
◆ play_on_awake() [2/2]
| void AudioSource::play_on_awake |
( |
bool |
value | ) |
|
|
noexcept |
◆ stop()
| void AudioSource::stop |
( |
| ) |
|
◆ type_name()
| std::string AudioSource::type_name |
( |
| ) |
const |
|
overridevirtual |
Provides a consistent type name for the component.
- Returns
- A string representing the type name of the component. @CAUTION: All derived components must implement this method to ensure consistent serialization across different compilers and platforms.
Implements Component.
◆ update()
| void AudioSource::update |
( |
float |
dt | ) |
|
|
overridevirtual |
◆ volume() [1/2]
| float AudioSource::volume |
( |
| ) |
const |
|
noexcept |
◆ volume() [2/2]
| void AudioSource::volume |
( |
float |
value | ) |
|
|
noexcept |
The documentation for this class was generated from the following file: