HumanBreak/docs/api/class/sound-effect.md
2024-03-01 19:52:30 +08:00

151 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 类 SoundEffect
渲染进程类,游戏进程不能直接使用,继承自 [`AudioPlayer`](./audio-player.md)
- 实例成员
- [`gain`](#gain)
- [`panner`](#panner)
- [`volume`](#volume)
- [`stereo`](#stereo)
- 实例方法
- 构造器[`constructor`](#constructor)
- [`protected initAudio`](#protected-initaudio)
- [`playSE`](#playse)
- [`stopAll`](#stopall)
- [`stopByIndex`](#stopbyindex)
- [`setPanner`](#setpanner)
- 静态成员
- [`playIndex`](#playindex)
- [`volume`](#static-volume)
- [`disable`](#disable)
## gain
```ts
declare var gain: GainNode
```
## panner
```ts
declare var panner: PannerNode
```
## volume
```ts
declare var volume: number
```
- 成员说明
当前音效的音量
## stereo
```ts
declare var stereo: boolean
```
- 成员说明
是否启用立体声
## constructor()
```ts
interface SoundEffect {
new(data: ArrayBuffer, stereo: boolean = true): SoundEffect
}
```
- 参数说明
- `data`: 音频的 `ArrayBuffer` 数据
- `stereo`: 是否启用立体声,默认启用
## protected initAudio()
```ts
declare function initAudio(stereo: boolean = true): void
```
- 方法说明
初始化音频,设置音频路由线路
- 不启用立体声source -> gain -> destination
- 启用立体声source -> panner -> gain -> destination
## playSE()
```ts
declare function playSE(): number
```
- 方法说明
播放这个音效
- 返回值
本次播放的唯一标识符
## stopAll()
```ts
declare function stopAll(): void
```
- 方法说明
停止这个音效的所有播放
## stopByIndex()
```ts
declare function stopByIndex(index: number): void
```
- 方法说明
根据播放的唯一标识符停止音效播放
## setPanner()
```ts
declare function setPanner(source?: Partial<Panner>, listener?: Partial<Listener>): void
```
- 方法说明
设置立体声信息,参考[立体声](../../guide/audio.md#播放立体声)
## playIndex
```ts
declare var playIndex: number
```
- 静态成员
## static volume
```ts
declare var volume: number
```
- 静态成员说明
控制所有音效的音量
## disable
```ts
declare var disable: boolean
```
- 静态成员说明
音效是否被关闭