Music autoplay

This commit is contained in:
Alexander Popov 2021-07-06 22:54:45 +03:00
parent c814f7715e
commit 769fe3ea9a
Signed by: iiiypuk
GPG Key ID: 398FC73478D97286
3 changed files with 8 additions and 5 deletions

View File

@ -1,11 +1,12 @@
## TODO:
- finish game image
- desktop (landscape) orientation
- background music
- change quest animation
- button hover animation
- make docs/
## done
## Done
- background music [c814f77]
- several correct answer [498ab55]
- loading all quest images with loading [b8aa4b6]
- splash (loading) screen [b8aa4b6]

View File

@ -3,5 +3,5 @@
"gameVersion": [0, 0, 1],
"debug": true,
"loaderWidth": 200,
"music": "music.mp3"
"music": { "src": "music.mp3", "autoplay": true }
}

View File

@ -1,7 +1,7 @@
export function playMusic(config, music) {
let request = new XMLHttpRequest();
request.open("GET", `assets/sfx/${config.music}`, true);
request.open("GET", `assets/sfx/${config.music.src}`, true);
request.responseType = "arraybuffer";
request.onload = function(){
music.decodeAudioData(request.response, onDecoded);
@ -12,7 +12,9 @@ export function playMusic(config, music) {
bufferSource.buffer = buffer;
bufferSource.connect(music.destination);
bufferSource.loop = true;
bufferSource.start();
if (config.music.autoplay)
bufferSource.start();
}
request.send();