|
@ -21,6 +21,7 @@ Sound.prototype.init = function () { |
|
|
const sounds = [ |
|
|
const sounds = [ |
|
|
{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }, |
|
|
{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }, |
|
|
{ src: 'sounds/audio1.mp3', id: 'audio1' }, |
|
|
{ src: 'sounds/audio1.mp3', id: 'audio1' }, |
|
|
|
|
|
{ src: 'sounds/audio2.mp3', id: 'audio2' }, |
|
|
]; |
|
|
]; |
|
|
const _this = this; |
|
|
const _this = this; |
|
|
createjs.Sound.addEventListener('fileload', function (event) { |
|
|
createjs.Sound.addEventListener('fileload', function (event) { |
|
@ -34,23 +35,23 @@ Sound.prototype.playBgm = function () { |
|
|
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
|
|
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Sound.prototype.playFootsteps = function () { |
|
|
|
|
|
console.log('播放脚步声: ', this.music.audio2); |
|
|
|
|
|
this.music.audio2 && this.music.audio2.play({ loop: -1 }); // 播放脚步声
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Sound.prototype.pauseFootsteps = function () { |
|
|
|
|
|
this.music.audio2 && this.music.audio2.pause(); // 停止脚步声
|
|
|
|
|
|
console.log('停止脚步声: ', this.music.audio2); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
Sound.prototype.playBomb = function (direction) { |
|
|
Sound.prototype.playBomb = function (direction) { |
|
|
if (direction === 0 || direction === 1) { |
|
|
if (direction === 0 || direction === 1) { |
|
|
this.music.audio1 && this.music.audio1.play(); // 播放爆炸声
|
|
|
this.music.audio1 && this.music.audio1.play(); // 播放跨栏声
|
|
|
|
|
|
this.music.audio2.paused = true; |
|
|
} |
|
|
} |
|
|
|
|
|
const _this = this; |
|
|
|
|
|
setTimeout(function () { |
|
|
|
|
|
_this.music.audio2.paused = false; |
|
|
|
|
|
}, 2000); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// let music = {};
|
|
|
|
|
|
// function initSound() {
|
|
|
|
|
|
// createjs.Sound.alternateExtensions = ['mp3'];
|
|
|
|
|
|
// const sounds = [
|
|
|
|
|
|
// { src: 'public/sounds/bgmMusic.mp3', id: 'bgm' },
|
|
|
|
|
|
// { src: 'public/sounds/excitationMusic.mp3', id: 'excitation' },
|
|
|
|
|
|
// { src: 'public/sounds/amazing.mp3', id: 'amazing' },
|
|
|
|
|
|
// { src: 'public/sounds/unbelievable.mp3', id: 'unbelievable' },
|
|
|
|
|
|
// ];
|
|
|
|
|
|
// createjs.Sound.addEventListener('fileload', function (event) {
|
|
|
|
|
|
// music[event.id] = createjs.Sound.createInstance(event.id);
|
|
|
|
|
|
// });
|
|
|
|
|
|
// createjs.Sound.registerSounds(sounds, '../../');
|
|
|
|
|
|
// }
|
|
|
|
|
|