audioOverlap

FLASH源码 2025-07-31

audioOverlap

一个简单的JavaScript解决方案,用于重叠音频对象和播放背景音乐。对HTML5游戏开发有用。

特征

  • 便于使用
  • 无需依赖项(纯JavaScript)
  • 克服HTML5与最小内存负载的重叠限制
  • 包括一个有用的背景音乐播放器,带有洗牌功能

用法

包括:

">
 

或者

">
 

音乐

添加背景音乐:

 addMusic("song1", "path/to/audioFile.mp3"); //Adds audio file with key: "song1"
addMusic("song2", "path/to/audioFile.mp3"); //Adds audio file with key: "song2"

设置播放的第一个曲目:

 setFirstTrack("song1"); //Sets the first track to play as "song1"

特定轨道的设置音量:

 setMusicVolume(0.5, "song1"); //Sets "song1" to 50% volume

所有轨道的设置卷:

 setMusicVolume(0.5); //Sets all music tracks to 50% volume

播放音乐(只需要一次打电话):

 playMusic(); //Initializes the music and starts playing. Only call this once.

切换音乐(播放/暂停):

 toggleMusic(); //Toggles music between playing and paused

奏乐:

 musicOn(); //Plays music if it is paused, useful if you have seperate play/pause buttons for music

暂停音乐:

 musicOff(); //Pauses music if it is playing, useful if you have seperate play/pause buttons for music

洗牌音乐(默认情况下):

 shuffleOn(); //Shuffles music tracks, will not repeat the same song twice in a row

不要洗牌音乐:

 shuffleOff(); //Does not shuffle music, will play through your music tracks in the order they have been added with addMusic()

循环音乐,因此它不断通过所有曲目播放(默认情况下):

 loopMusicOn(); //Loops through your playlist repeatedly

请勿循环音乐,所以它只播放一首歌(除非您完全了解此代码的工作方式,否则请勿使用。可用于特定情况):

 loopMusicOff(); //Prevents looping, only plays one song

声音效果

添加声音效果:

 addSFX("effect1", "path/to/audioFile.wav", 4); //Adds 4 of "effect1" to the sound effect pool. 4 can be played overlapping.
addSFX("effect2", "path/to/audioFile.wav", 10); //Adds 10 of "effect2" to the sound effect pool. 10 can be played overlapping.

播放声音效果:

 playSFX("effect1"); //Plays "effect1" if it is available in the sound effect pool.

设置特定声音效果的卷:

 setSFXVolume(0.5, "effect1"); //Sets "effect1" to 50% volume

所有声音效果的设置卷:

 setSFXVolume(0.5); //Sets all sound effects to 50% voume

切换声音效果(静音/取消静音):

 toggleSFX(); //Toggles sound effects between mute/unmute

打开声音效果(默认情况下):

 SFXOn(); //Turns on sound effects, useful if you have seperate on/off buttons for sound effects

关闭声音效果:

 SFXOff(); //Turns off sound effects, useful if you have seperate on/off buttons for sound effects
下载源码

通过命令行克隆项目:

git clone https://github.com/chadcromwell/audioOverlap.git