ShitEngine 1.4.2
基于 C++20 与 SDL3 的轻量级 2D 游戏引擎
载入中...
搜索中...
未找到
AudioSource类 参考

音频播放组件 —— 挂在对象上播放场景音频 更多...

#include <AudioSource.h>

类 AudioSource 继承关系图:
Behavior Component

Public 成员函数

 AudioSource ()=default
void setAudioPath (const std::string &path)
const std::string & getAudioPath () const
void setLoop (bool loop)
bool isLoop () const
void setVolume (float volume)
 音量 0~1
float getVolume () const
void setPlayOnStart (bool playOnStart)
bool isPlayOnStart () const
void play ()
 按 AudioPath 播放(遵循 Loop / Volume)
void stop ()
void pause ()
void onStart () override
 首次 update 前执行一次
Public 成员函数 继承自 Behavior
 Behavior ()=default
 ~Behavior () override=default
void onCreate () override
void onAttach () override
virtual void onFixedUpdate (float fixedDt)
 固定步长执行(与物理同拍;Scene 固定步循环驱动)
virtual void onUpdate ()
 每帧执行
virtual void onCollisionEnter (GameObject *other)
 与 other 开始接触(每对象对一次)
virtual void onCollisionStay (GameObject *other)
 与 other 持续接触(每帧一次)
virtual void onCollisionExit (GameObject *other)
 与 other 结束接触
void onDetach () override
void onDestroy () override
bool isStarted () const
 onStart 是否已执行过
void setStarted (bool isStarted)
Public 成员函数 继承自 Component
 Component ()
virtual ~Component ()=default
virtual void onAfterDeserialize ()
 反序列化完成后回调(Prefab::apply 逐组件调用一次,字段已写入)。 用于重建"直写字段绕过了 setter、无法自动触发的引擎状态"(如精灵纹理加载)。
virtual void onFieldChanged (const std::string &fieldName)
 检查器直接写反射字段后回调(字段名)。用于绕过 setter 的直写完成后 重新同步引擎状态(如 Box2D 刚体/形状)。默认无操作。
 Component (const Component &)=delete
Component & operator= (const Component &)=delete
 Component (Component &&)=delete
Component & operator= (Component &&)=delete
GameObject * getOwner () const
bool isRegistered () const
uint64_t getUuid () const
 组件持久 ID(随 .scene 序列化,是 ComponentRef<T> 引用字段的寻址依据)
void setUuid (uint64_t uuid)
 直接设置组件 ID(仅引擎反序列化/索引维护使用;正常流程由构造函数随机分配)

额外继承的成员函数

Protected 成员函数 继承自 Component
void setRegistered (bool registered)
Protected 属性 继承自 Behavior
bool m_isStarted = false
Protected 属性 继承自 Component
GameObject * m_owner = nullptr
bool m_isRegistered = false
uint64_t m_uuid = 0
 持久 ID(构造时随机分配;0 仅在序列化前尚未赋值时短暂存在)

详细描述

音频播放组件 —— 挂在对象上播放场景音频

继承 Behavior(与 AnimationComponent 一致),由 BehaviorSystem 驱动: onStart 时按 PlayOnStart 自动播放;脚本中也可手动 play()/stop()/pause()。

音频路径与纹理同一约定(相对资源目录),播放句柄为共享引用—— 播完引擎自动回收;重新 play() 新建轨道替换旧句柄。

构造及析构函数说明

◆ AudioSource()

AudioSource ( )
default

成员函数说明

◆ getAudioPath()

const std::string & getAudioPath ( ) const
inline

◆ getVolume()

float getVolume ( ) const
inline

◆ isLoop()

bool isLoop ( ) const
inline

◆ isPlayOnStart()

bool isPlayOnStart ( ) const
inline

◆ onStart()

void onStart ( )
overridevirtual

首次 update 前执行一次

重载 Behavior .

◆ pause()

void pause ( )

◆ play()

void play ( )

按 AudioPath 播放(遵循 Loop / Volume)

◆ setAudioPath()

void setAudioPath ( const std::string & path)

◆ setLoop()

void setLoop ( bool loop)

◆ setPlayOnStart()

void setPlayOnStart ( bool playOnStart)

◆ setVolume()

void setVolume ( float volume)

音量 0~1

◆ stop()

void stop ( )

该类的文档由以下文件生成: