Commit 616e4cb8 by Mike Zhu

feat: 使onSocketMessage通知更新Scene

parent 4af542f5
...@@ -111,6 +111,14 @@ class Main extends egret.DisplayObjectContainer { ...@@ -111,6 +111,14 @@ class Main extends egret.DisplayObjectContainer {
platform.onSocketMessage(function(res) { platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data) console.log('收到服务器内容:' + res.data)
const state = Store.onMessage(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') {
SceneManager.getInstance().roomScene.update(data)
}
}) })
platform.onSocketError((e) => { platform.onSocketError((e) => {
console.error("onSocketError") console.error("onSocketError")
......
...@@ -2,9 +2,9 @@ class SceneManager extends egret.DisplayObjectContainer { ...@@ -2,9 +2,9 @@ class SceneManager extends egret.DisplayObjectContainer {
// 场景控制器的单例 // 场景控制器的单例
private static instance: SceneManager; private static instance: SceneManager;
// 开始场景 // 开始场景
private roomScene: RoomScene; public roomScene: RoomScene;
// 游戏场景 // 游戏场景
private gameScene: GameScene; public gameScene: GameScene;
public constructor() { public constructor() {
super(); super();
...@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer { ...@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this.roomScene = new RoomScene(); this.roomScene = new RoomScene();
this.gameScene = new GameScene(); this.gameScene = new GameScene();
// 默认添加开始场景 // 默认添加开始场景
this.addChild(this.gameScene); this.addChild(this.roomScene);
} }
// 实例化单例获取方法 // 实例化单例获取方法
public static getInstance(): SceneManager { public static getInstance(): SceneManager {
......
...@@ -13,37 +13,20 @@ class RoomScene extends egret.Sprite { ...@@ -13,37 +13,20 @@ class RoomScene extends egret.Sprite {
console.log('RoomScene.init') console.log('RoomScene.init')
this.initBg() this.initBg()
this.initStartLabel() this.initStartLabel()
// platform.sendSocketMessage({
// data: JSON.stringify({
// type: 'entry',
// rid: 'default_room',
// payload: {
// avatar_url: Store.getState().userInfo.avatarUrl,
// nick_name: Store.getState().userInfo.nickName
// }
// }),
// success: res => {
// console.error("sendSocketMessage success")
// },
// fail: res => {
// console.error("sendSocketMessage fail")
// },
// complete: res => {
// }
// })
platform.onSocketMessage(res => {
if (res.type === 'entry') {
console.log('get entry data')
}
})
// this.startLabel.text = "START";
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this);
this.addChild(this.startLabel); this.addChild(this.startLabel);
// put display object to this scene // put display object to this scene
} }
public update(data) {
const payload = data.payload
if(payload.seat == 0) {
this.startLabel.text = '开始'
this.startLabel.touchEnabled = true
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
}
}
private initBg() { private initBg() {
var shape: egret.Shape = new egret.Shape(); var shape: egret.Shape = new egret.Shape();
shape.graphics.beginFill(0x343E5F); shape.graphics.beginFill(0x343E5F);
......
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