Commit 461a7523 by Mike Zhu

更新所有玩家倒计时

parent 9ff81dfe
......@@ -109,20 +109,23 @@ class Main extends egret.DisplayObjectContainer {
})
this.createGameScene();
platform.onSocketMessage(function(res) {
platform.onSocketMessage(function (res) {
console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(res.data)
let data = res.data
if (typeof res.data === 'string') {
data = JSON.parse(res.data)
}
if(data.type === 'entry') {
switch (data.type) {
case 'entry':
Store.onMessage({
type: 'updateCid',
payload: data
})
SceneManager.getInstance().roomScene.update(data)
break;
case 'game_ready':
SceneManager.getInstance().roomScene.update(data)
}
}
})
platform.onSocketError((e) => {
......
......@@ -26,11 +26,13 @@ class Store {
..._state,
userInfo: payload
}
break;
case 'updateCid':
_state = {
..._state,
cid: payload.cid
}
break;
default:
break;
}
......
......@@ -19,6 +19,8 @@ class RoomScene extends egret.Sprite {
}
public update(data) {
switch (data.type) {
case 'entry':
const payload = data.payload
if (payload.seat == 0) {
this.startLabel.text = '开始'
......@@ -28,6 +30,28 @@ class RoomScene extends egret.Sprite {
this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false
}
break;
case 'game_ready':
this.countDown(payload)
default:
break;
}
}
private countDown(res) {
this.startLabel.text = '3'
const timer = setInterval(() => {
if (this.startLabel.text == '1') {
return this.startLabel.text = 'Go!'
}
if (this.startLabel.text == 'Go!') {
clearInterval(timer)
SceneManager.getInstance().changeScene('gameScene')
return
}
this.startLabel.text = `${Number(this.startLabel.text) - 1}`
}, 1000)
}
private initBg() {
......@@ -67,21 +91,10 @@ class RoomScene extends egret.Sprite {
}
}),
success: res => {
this.startLabel.text = '3'
const timer = setInterval(() => {
if(this.startLabel.text == '1') {
return this.startLabel.text = 'Go!'
}
if(this.startLabel.text == 'Go!') {
clearInterval(timer)
SceneManager.getInstance().changeScene('gameScene')
return
}
this.startLabel.text = `${Number(this.startLabel.text) - 1}`
}, 1000)
},
fail: res => {
this.startLabel.text = '启动失败'
console.error('start error: ', res)
}
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment