FmodAudioStreamPlayer2D#
继承: Node2D < CanvasItem < Node < Object
用于在 2D 场景中播放带距离衰减和声像的音频流
描述#
播放 FmodAudioStream ,根据与 2D 监听器的距离和方位调整衰减与立体声声像。每个播放器使用一个播放通道。
属性#
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法#
void |
set_stream(stream: FmodAudioStream) |
get_stream() const |
|
void |
|
void |
|
void |
stop() |
void |
set_playing(playing: bool) |
is_playing() const |
|
void |
set_stream_paused(paused: bool) |
get_stream_paused() const |
|
get_playback_position() const |
|
void |
set_volume_db(volume_db: float) |
get_volume_db() const |
|
void |
set_volume_linear(volume_linear: float) |
get_volume_linear() const |
|
void |
set_pitch_scale(pitch_scale: float) |
get_pitch_scale() const |
|
void |
set_autoplay(enable: bool) |
is_autoplay_enabled() const |
|
void |
set_preload_on_set_stream(enable: bool) |
is_preload_on_set_stream_enabled() const |
|
void |
set_max_distance(pixels: float) |
get_max_distance() const |
|
void |
set_attenuation(curve: float) |
get_attenuation() const |
|
void |
set_panning_strength(panning_strength: float) |
get_panning_strength() const |
|
void |
set_bus(bus: StringName) |
get_bus() const |
|
void |
set_area_mask(mask: int) |
get_area_mask() const |
|
void |
set_max_polyphony(max_polyphony: int) |
get_max_polyphony() const |
|
has_stream_playback() const |
|
get_stream_playback() const |
信号#
finished()
属性说明#
FmodAudioStream stream
void set_stream(stream: FmodAudioStream)
FmodAudioStream get_stream() const
要播放的音频流资源 (参见 FmodAudioStream )
bool playing = false
设置为 true 开始播放,设置为 false 停止播放
bool stream_paused = false
是否暂停当前播放流
float volume_db = 0.0
基础音量,单位为分贝
float pitch_scale = 1.0
播放速度和音高缩放
bool autoplay = false
为 true 时,在节点就绪后延迟开始播放,在编辑器中不生效。
bool preload_on_set_stream = false
设置 stream 时是否立即预加载内部 FmodSound
float max_distance = 2000.0
以像素表示的距离衰减范围,最小为 1.0 。监听器距离大于此值时,播放器将通道音量设为 -80.0 dB。
float attenuation = 1.0
距离衰减曲线强度
float panning_strength = 1.0
左右声像强度
StringName bus = &"Master"
void set_bus(bus: StringName)
StringName get_bus() const
输出到的音频总线名称
int area_mask = 1
保存的区域掩码。尚未实现基于区域的音频过滤。
int max_polyphony = 1
保存请求的声部上限,最小为 1 。此播放器目前只使用一个通道,该设置不会启用重叠播放。
方法说明#
void set_stream(stream: FmodAudioStream)
停止当前播放并设置 stream ,之后需调用 play() 开始播放。
FmodAudioStream get_stream() const
返回当前设置的音频流 (参见 FmodAudioStream )
未设置音频流时返回 null 。
bool preload_stream()
通过创建内部 FmodSound 预加载音频流。未设置音频流或声音创建失败时返回 false 。
void play(from_position: float = 0.0)
从 from_position 指定的位置开始或重新播放,单位为秒。位置应为非负数。
void seek(to_position: float)
跳转到指定播放位置,单位为秒
播放或暂停时均可调用。
void stop()
停止播放并清除暂停状态
void set_playing(playing: bool)
控制播放状态。设置为 true 会从头开始播放。
设为 false 会停止播放。
bool is_playing() const
播放通道处于活动状态时返回 true ,暂停时也返回 true 。
void set_stream_paused(paused: bool)
暂停或恢复当前播放流
bool get_stream_paused() const
返回当前播放流的暂停状态
float get_playback_position() const
返回播放位置,单位为秒,暂停时仍可查询。没有有效播放通道时返回 0.0 。
void set_volume_db(volume_db: float)
设置基础音量,单位为分贝
0.0 为单位增益;负值衰减,正值放大(若支持)。
float get_volume_db() const
返回基础音量,单位为分贝
默认值为 0.0 dB,即单位增益。
void set_volume_linear(volume_linear: float)
使用线性音量设置基础音量
内部会转换为分贝。
float get_volume_linear() const
以线性音量返回基础音量
从内部的分贝值转换为线性值。
void set_pitch_scale(pitch_scale: float)
设置播放速度和音高缩放
1.0 为正常音高。较大的值会提高音高和播放速度。
float get_pitch_scale() const
返回当前播放速度和音高缩放
1.0 为默认音高, 0.5 降低一个八度, 2.0 升高一个八度。
void set_autoplay(enable: bool)
设置 autoplay 。自动播放会延迟到节点就绪后执行,在编辑器中不生效。
bool is_autoplay_enabled() const
返回是否启用了 autoplay 。
void set_preload_on_set_stream(enable: bool)
设置是否在赋值 stream 时立即预加载。
bool is_preload_on_set_stream_enabled() const
如果启用了赋值时预加载,则返回 true 。
void set_max_distance(pixels: float)
以像素表示的距离衰减范围,最小为 1.0 。监听器距离大于此值时,播放器将通道音量设为 -80.0 dB。
float get_max_distance() const
以像素表示的距离衰减范围,最小为 1.0 。监听器距离大于此值时,播放器将通道音量设为 -80.0 dB。
void set_attenuation(curve: float)
设置距离衰减曲线强度
1.0 表示线性衰减。值越大,随距离衰减越快。
float get_attenuation() const
返回距离衰减曲线强度
值越大,音量随距离衰减得越快。
void set_panning_strength(panning_strength: float)
设置左右声像强度
值越大,左右声像变化越明显。
设为 0.0 可关闭声像调整。
float get_panning_strength() const
返回左右声像强度
值越大,左右声像变化越明显。
默认值为 1.0 。
void set_bus(bus: StringName)
设置下次创建播放通道时使用的总线。修改此值不会改变现有通道的路由。
在 FmodAudioBusLayout 中找不到该总线时,播放使用主通道组。
StringName get_bus() const
返回当前输出总线名称
默认值为 &"Master" 。
void set_area_mask(mask: int)
保存 mask 。此播放器尚未实现基于区域的音频过滤。
int get_area_mask() const
返回保存的区域掩码,此值目前不影响播放。
void set_max_polyphony(max_polyphony: int)
保存请求的声部上限,最小为 1 。此播放器目前只使用一个通道,该设置不会启用重叠播放。
int get_max_polyphony() const
返回保存的声部上限。此播放器目前只使用一个播放通道。
bool has_stream_playback() const
如果内部通道对象有效,则返回 true
FmodChannel get_stream_playback() const
返回内部播放通道,可用于高级控制 (参见 FmodChannel )
没有活动通道时返回 null 。
可用于进一步控制正在播放的声音。