Browse Source

fix:倒计时bug

master
wally 4 years ago
parent
commit
bfb2113b81
  1. 5
      index.js

5
index.js

@ -15,6 +15,7 @@ const obj = {
btnAgain: null, // 再玩一次的按钮 btnAgain: null, // 再玩一次的按钮
bgModalBegin: null, // 开始倒计时面板 bgModalBegin: null, // 开始倒计时面板
countTimer: null, // 开始游戏的倒计时的 计时器id countTimer: null, // 开始游戏的倒计时的 计时器id
initCount: 5, // 默认倒计时时长
count: 5, // 开始游戏时的倒计时 count: 5, // 开始游戏时的倒计时
music: { music: {
bgm: null, // 背景音乐 bgm: null, // 背景音乐
@ -134,7 +135,7 @@ function initBeginCount() {
stage.removeChild(obj.btnBegin); // 移除开始游戏的按钮 stage.removeChild(obj.btnBegin); // 移除开始游戏的按钮
const startTime = +gameInfo.startTime; const startTime = +gameInfo.startTime;
const endCountTime = startTime + obj.count * 1000; const endCountTime = startTime + obj.initCount * 1000;
obj.count = Math.floor((endCountTime - Date.now()) / 1000); obj.count = Math.floor((endCountTime - Date.now()) / 1000);
changeBeginTime(obj.count); // 开始开始游戏的 倒计时 changeBeginTime(obj.count); // 开始开始游戏的 倒计时
@ -426,7 +427,7 @@ function sendEndRequest() {
// 处理倒计时 // 处理倒计时
function interval() { function interval() {
if (obj.timerId) return; if (obj.timerId) return;
const endTime = +gameInfo.startTime + 10 * 1000 + +gameInfo.duration; const endTime = +gameInfo.startTime + obj.initCount * 1000 + +gameInfo.duration;
obj.timerId = setInterval(function () { obj.timerId = setInterval(function () {
if (obj.totalTime === 0) { if (obj.totalTime === 0) {
gameOver(); gameOver();

Loading…
Cancel
Save