Spaces:
Running
Running
Update game.js
Browse files
game.js
CHANGED
@@ -684,27 +684,41 @@ class Game {
|
|
684 |
startBGM() {
|
685 |
if (this.bgmPlaying) return;
|
686 |
|
|
|
|
|
687 |
try {
|
688 |
this.bgm = new Audio('sounds/main.ogg');
|
689 |
this.bgm.volume = 0.5;
|
690 |
this.bgm.loop = true;
|
691 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
// μ¦μ μ¬μ μλ
|
693 |
const playPromise = this.bgm.play();
|
694 |
|
|
|
|
|
695 |
if (playPromise !== undefined) {
|
696 |
playPromise.then(() => {
|
697 |
this.bgmPlaying = true;
|
698 |
-
console.log('BGM μ¬μ μμ');
|
699 |
}).catch(error => {
|
700 |
-
console.log('μλ μ¬μμ΄
|
|
|
701 |
|
702 |
// μ¬μ©μ μνΈμμ© ν μ¬μ μ¬μλ
|
703 |
const tryPlayOnInteraction = () => {
|
704 |
if (!this.bgmPlaying) {
|
|
|
705 |
this.bgm.play().then(() => {
|
706 |
this.bgmPlaying = true;
|
707 |
-
console.log('BGM μ¬μ μμ (ν΄λ¦ ν)');
|
708 |
// μ΄λ²€νΈ 리μ€λ μ κ±°
|
709 |
document.removeEventListener('click', tryPlayOnInteraction);
|
710 |
document.removeEventListener('keydown', tryPlayOnInteraction);
|
|
|
684 |
startBGM() {
|
685 |
if (this.bgmPlaying) return;
|
686 |
|
687 |
+
console.log('BGM μμ μλ...');
|
688 |
+
|
689 |
try {
|
690 |
this.bgm = new Audio('sounds/main.ogg');
|
691 |
this.bgm.volume = 0.5;
|
692 |
this.bgm.loop = true;
|
693 |
|
694 |
+
console.log('Audio κ°μ²΄ μμ± μλ£');
|
695 |
+
|
696 |
+
// μ€λμ€ μ΄λ²€νΈ 리μ€λ μΆκ°
|
697 |
+
this.bgm.addEventListener('loadstart', () => console.log('BGM λ‘λ© μμ'));
|
698 |
+
this.bgm.addEventListener('canplay', () => console.log('BGM μ¬μ κ°λ₯'));
|
699 |
+
this.bgm.addEventListener('error', (e) => console.log('BGM μλ¬:', e));
|
700 |
+
this.bgm.addEventListener('loadeddata', () => console.log('BGM λ°μ΄ν° λ‘λ μλ£'));
|
701 |
+
|
702 |
// μ¦μ μ¬μ μλ
|
703 |
const playPromise = this.bgm.play();
|
704 |
|
705 |
+
console.log('μ¬μ μλ μ€...');
|
706 |
+
|
707 |
if (playPromise !== undefined) {
|
708 |
playPromise.then(() => {
|
709 |
this.bgmPlaying = true;
|
710 |
+
console.log('BGM μ¬μ μμ μ±κ³΅!');
|
711 |
}).catch(error => {
|
712 |
+
console.log('μλ μ¬μμ΄ μ°¨λ¨λ¨:', error);
|
713 |
+
console.log('ν΄λ¦ ν μ¬μ μλ λκΈ° μ€...');
|
714 |
|
715 |
// μ¬μ©μ μνΈμμ© ν μ¬μ μ¬μλ
|
716 |
const tryPlayOnInteraction = () => {
|
717 |
if (!this.bgmPlaying) {
|
718 |
+
console.log('μ¬μ©μ μνΈμμ©μΌλ‘ BGM μ¬μ μλ...');
|
719 |
this.bgm.play().then(() => {
|
720 |
this.bgmPlaying = true;
|
721 |
+
console.log('BGM μ¬μ μμ μ±κ³΅ (ν΄λ¦ ν)!');
|
722 |
// μ΄λ²€νΈ 리μ€λ μ κ±°
|
723 |
document.removeEventListener('click', tryPlayOnInteraction);
|
724 |
document.removeEventListener('keydown', tryPlayOnInteraction);
|