Browse Source

修改动作音频

master
song 4 years ago
parent
commit
8069ece78d
  1. BIN
      public/RECOVER_source-code.fla
  2. 4
      public/index.html
  3. BIN
      public/source-code.fla
  4. 23
      public/source-code.js
  5. 20
      src/classes/main.js
  6. 19
      src/classes/sound.js
  7. 1
      src/classes/time.js

BIN
public/RECOVER_source-code.fla

Binary file not shown.

4
public/index.html

@ -36,9 +36,5 @@
<span style='display: inline-block; height: 100%; vertical-align: middle;'></span>
<img src=images/_preloader.gif style='vertical-align: middle; max-height: 100%'/>
</div>
<!-- 音频 -->
<audio src="sounds/audio1.mp3" id="audio1" controls="controls" hidden="true"></audio>
<audio src="sounds/audio2.mp3" id="audio2" controls="controls" hidden="true"></audio>
<audio src="sounds/audio3.mp3" id="audio3" controls="controls" hidden="true"></audio>
</body>
</html>

BIN
public/source-code.fla

Binary file not shown.

23
public/source-code.js

File diff suppressed because one or more lines are too long

20
src/classes/main.js

@ -52,10 +52,12 @@ Main.prototype.play = function (direction) {
if (Date.now() - this.prevTime <= 1200 || state !== 1) return;
// if (state !== 1) return;
this.element.play();
// 一进来动画移动到指定位置
if (direction === 99) return;
this.times += 1;
this.computeScore(this.times, direction);
this.setMusic(direction);
this.prevTime = Date.now();
if (this.times >= this.max) {
@ -73,22 +75,8 @@ Main.prototype.computeScore = function (times, direction = 0) {
const directionTarget = config.config.scores.find(item => item.direction === direction);
config.currentTimes = times;
config.currentScore += directionTarget.score;
window.soundInstance.playBomb(direction);
if (config.mode === 0) {
sendMessage({ event: 'play', data: { currentTimes: times, currentScore: config.currentScore } });
}
};
Main.prototype.setMusic = function (direction) {
let audio1 = document.getElementById('audio1');
let audio2 = document.getElementById('audio2');
let audio3 = document.getElementById('audio3');
if (direction === 0) {
audio1.play();
}
if (direction === 1) {
audio2.play();
}
if (direction === 2) {
audio3.play();
}
};

19
src/classes/sound.js

@ -18,7 +18,12 @@ Sound.of = (function () {
Sound.prototype.init = function () {
createjs.Sound.alternateExtensions = ['mp3'];
const sounds = [{ src: 'sounds/bgmMusic.mp3', id: 'bgm' }];
const sounds = [
{ src: 'sounds/bgmMusic.mp3', id: 'bgm' },
{ src: 'sounds/audio1.mp3', id: 'audio1' },
{ src: 'sounds/audio2.mp3', id: 'audio2' },
{ src: 'sounds/audio3.mp3', id: 'audio3' },
];
const _this = this;
createjs.Sound.addEventListener('fileload', function (event) {
_this.music[event.id] = createjs.Sound.createInstance(event.id);
@ -31,6 +36,18 @@ Sound.prototype.playBgm = function () {
this.music.bgm && this.music.bgm.play({ loop: -1, volume: 0.3 }); // 播放背景音乐
};
Sound.prototype.playBomb = function (direction) {
if (direction === 0) {
this.music.audio1 && this.music.audio1.play();
}
if (direction === 1) {
this.music.audio2 && this.music.audio2.play();
}
if (direction === 2) {
this.music.audio3 && this.music.audio3.play();
}
};
// let music = {};
// function initSound() {
// createjs.Sound.alternateExtensions = ['mp3'];

1
src/classes/time.js

@ -65,6 +65,7 @@ Time.prototype.start = function (startTime = Date.now()) {
this.startTime = startTime;
this.duration = leftDuration ? leftDuration : this.duration;
this.update();
main.play(99);
};
// 暂停游戏 暂停倒计时

Loading…
Cancel
Save