vanilladocs
vanillapunch.com
API / core/soundeffectpool

core/soundeffectpool

효과음 풀.

  • 원본 core/soundeffectpool.js. 같은 효과음이 연달아 겹쳐 나도 끊기지 않도록 여러 AudioPlayer 를 돌려 가며(라운드로빈) 재생한다.
  • 백엔드를 직접 부르지 않는다. AudioPlayer 위에서 차례와 음량만 센다.
  • 사용:
let mut sound_effect_pool = SoundEffectPool::new(&engine.get_audio_manager(), 6);
sound_effect_pool.play(&hitAudioAsset, 1.0);
sound_effect_pool.play(&hitAudioAsset, 0.5);   // 이 재생만 절반 음량.
sound_effect_pool.set_volume(0.8);              // 풀 전체의 음량. (재생 중인 것에도 곱해진다)
  • 보이스 수가 0 이면 play 는 원본처럼 아무것도 하지 않는다.
  • 원본과 다른 점:
play 의 음량은 기본값이 없어 늘 넘긴다. (원본 기본 1)

Sound effect pool.

  • The original core/soundeffectpool.js. So the same sound effect is not cut off when it overlaps in quick succession, it plays by rotating through several AudioPlayers (round robin).
  • Does not call the backend directly. On top of AudioPlayer it only tracks the turn and volume.
  • Usage:
let mut sound_effect_pool = SoundEffectPool::new(&engine.get_audio_manager(), 6);
sound_effect_pool.play(&hitAudioAsset, 1.0);
sound_effect_pool.play(&hitAudioAsset, 0.5);   // Half volume for this playback only.
sound_effect_pool.set_volume(0.8);              // Volume of the whole pool. (also multiplied into ones already playing)
  • If the voice count is 0, play does nothing, as in the original.
  • Differences from the original:
play's volume has no default, so it is always passed. (the original defaults to 1)

SoundEffectPoolstruct

짝Counterpart: vanilla.js SoundEffectPool소스source

효과음 풀.

  • 플레이어 여럿을 차례로 돌려 같은 효과음이 겹쳐도 앞 소리를 끊지 않는다. (보이스 수보다 많이 겹치면 가장 오래된 것을 끊는다)

Sound effect pool.

  • Rotates through several players in turn so overlapping copies of the same sound effect do not cut off the earlier sound. (if more overlap than the voice count, the oldest is cut)
예제Example보이스 6 개 풀로 효과음 겹쳐 틀기Play overlapping sound effects with a 6-voice pool
use vanilla::{Engine, EngineConfiguration, SoundEffectPool};

let engine = Engine::new(EngineConfiguration::new());
let hit_audio_asset = engine.load_audio_asset("tests/assets/audio/wav_s16_stereo.wav").unwrap();
let mut sound_effect_pool = SoundEffectPool::new(&engine.get_audio_manager(), 6);
sound_effect_pool.play(&hit_audio_asset, 1.0);
sound_effect_pool.play(&hit_audio_asset, 0.5);
sound_effect_pool.set_volume(0.8);
assert_eq!(sound_effect_pool.get_voice_count(), 6);
예제Example보이스가 없는 풀은 재생하지 않고 음량만 든다A pool with no voices does not play and only holds the volume
use vanilla::{AudioManager, SoundEffectPool};

let audio_manager = AudioManager::new();
let mut sound_effect_pool = SoundEffectPool::new(&audio_manager, 0);
assert_eq!(sound_effect_pool.get_voice_count(), 0);
sound_effect_pool.set_volume(1.5);
assert_eq!(sound_effect_pool.get_volume(), 1.0);
sound_effect_pool.set_muted(true);
assert!(sound_effect_pool.is_muted());
생성자constructorpub fn new(audio_manager: &AudioManager, voice_count: usize) -> SoundEffectPool#0.3.2 부터since 0.3.2소스source

생성. (voice_count: 동시에 겹칠 수 있는 최대 재생 수)

Creates. (voice_count: maximum number of playbacks that can overlap at once)

audio_manager&AudioManager
플레이어를 만들 매니저. (보통 engine.get_audio_manager())Manager to create the players with. (usually engine.get_audio_manager())
voice_countusize
동시에 겹칠 수 있는 최대 재생 수. (원본 기본 6, DEFAULT_VOICE_COUNT) 0 이면 play 가 아무것도 하지 않는다.Maximum number of playbacks that can overlap at once. (the original default 6, DEFAULT_VOICE_COUNT) If 0, play does nothing.

반환ReturnsSoundEffectPool 플레이어 voice_count 개를 든 새 풀. (음량 1, 음소거 아님)A new pool holding voice_count players. (volume 1, not muted)

짝Counterpart: vanilla.js SoundEffectPool.constructor

메서드methodpub fn play(&mut self, audio_asset: &Rc<AudioAsset>, volume: f64)#0.3.2 부터since 0.3.2소스source

효과음 재생.

  • 다음 차례의 플레이어에 애셋을 실어 재생한다. 그 플레이어가 재생 중이었다면 끊고 새로 튼다.
  • 음량은 이 재생의 음량(0 ~ 1)에 풀의 음량을 곱한 것이다.
  • 음소거 중이거나 보이스가 없으면 아무것도 하지 않고 차례도 넘기지 않는다.

Plays a sound effect.

  • Loads the asset into the next player in turn and plays it. If that player was playing, cuts it and plays anew.
  • The volume is this playback's volume (0 ~ 1) multiplied by the pool's volume.
  • While muted or without voices, does nothing and does not advance the turn.
audio_asset&Rc<AudioAsset>
틀 효과음 애셋.Sound effect asset to play.
volumef64
이 재생의 음량. (0 ~ 1, 풀의 음량을 곱한 뒤 0 ~ 1 로 자른다)Volume of this playback. (0 ~ 1, multiplied by the pool's volume then clamped to 0 ~ 1)

짝Counterpart: vanilla.js SoundEffectPool.play

메서드methodpub fn stop_all(&mut self)#0.3.2 부터since 0.3.2소스source

모두 정지.

Stops all.

짝Counterpart: vanilla.js SoundEffectPool.stopAll

메서드methodpub fn set_muted(&mut self, is_muted: bool)#0.3.2 부터since 0.3.2소스source

음소거 설정.

  • 모든 플레이어를 음소거하거나 풀고, 음소거 중에는 play 를 건너뛴다.

Sets mute.

  • Mutes or unmutes all players, and skips play while muted.
is_mutedbool
true 면 음소거, false 면 풀기.True to mute, false to unmute.

짝Counterpart: vanilla.js SoundEffectPool.setMuted

메서드methodpub fn set_volume(&mut self, volume: f64)#0.3.2 부터since 0.3.2소스source

풀 전체의 음량 설정. (0 ~ 1, 재생 중인 것에도 바로 곱해진다)

Sets the volume of the whole pool. (0 ~ 1, applied immediately to those playing too)

volumef64
풀 전체의 음량. (0 ~ 1 로 자른다, 유한하지 않으면 1)Volume of the whole pool. (clamped to 0 ~ 1, 1 if not finite)

짝Counterpart: vanilla.js SoundEffectPool.setVolume

메서드methodpub fn get_volume(&self) -> f64#0.3.2 부터since 0.3.2소스source

풀 전체의 음량.

Volume of the whole pool.

반환Returnsf64 풀 전체의 음량. (0 ~ 1, 기본 1)Volume of the whole pool. (0 ~ 1, default 1)

짝Counterpart: vanilla.js SoundEffectPool.getVolume

메서드methodpub fn is_muted(&self) -> bool#0.3.2 부터since 0.3.2소스source

음소거 여부.

Whether muted.

반환Returnsbool set_muted(true) 뒤면 true.True after set_muted(true).

짝Counterpart: vanilla.js SoundEffectPool.isMuted

메서드methodpub fn get_voice_count(&self) -> usize#0.3.2 부터since 0.3.2소스source

보이스 수 반환.

Returns the number of voices.

반환Returnsusize 풀이 든 플레이어 수. (만들 때의 voice_count)Number of players the pool holds. (voice_count at creation)

짝Counterpart: vanilla.js SoundEffectPool.getVoiceCount

상수Constants

상수constantpub const DEFAULT_VOICE_COUNT: usize = 6#0.3.2 부터since 0.3.2소스source

원본 생성자의 기본 보이스 수.

Default voice count of the original constructor.

반환Returnsusize