Hi,
I am trying to create a JavaScript array of Phaser 3 audio.
I have below but it errors out when viewed in browser:
var MusicTemp;
const Music = [];
this.load.setPath('data/music');
this.load.audio('MusicTemp', [ 'BGM_Title.mp3' ]);
Music = this.sound.add('MusicTemp');
Any help would be appreciated, thanks!
Jesse
Web demo can be played on Itch website below:
Play in your browser
Hi, did something different which I am happy with:
var SFX_Player_Jump;
var SFX_Collect_Star;
var SFX_Player_Hit_By_Bomb;
var SFX_New_Bomb;
var BGM_Music;
function LoadAllAudio ()
{
this.load.setPath('data/sound');
this.load.audio('SFX_Player_Jump', [ 'SFX_Player_Jump.mp3' ]);
this.load.audio('SFX_Collect_Star', [ 'SFX_Collect_Star.mp3' ]);
this.load.audio('SFX_Player_Hit_By_Bomb', [ 'SFX_Player_Hit_By_Bomb.mp3' ]);
this.load.audio('SFX_New_Bomb', [ 'SFX_New_Bomb.mp3' ]);
this.load.setPath('data/music');
this.load.audio('BGM_Music', [ 'BGM_Title.mp3' ]);
}
function PlaySoundEffect (index, volume, loop)
{
index.setVolume(volume);
index.setLoop(loop);
index.play();
}
function PlayMusic (index, volume, loop)
{
index.setVolume(volume);
index.setLoop(loop);
index.play();
}
samme
April 13, 2023, 1:44am
3
For one-and-done playback, you can skip sound.add()
and do
this.sound.play('SFX_Collect_Star', { loop: false, volume: 1 });