Commit 616e4cb8 by Mike Zhu

feat: 使onSocketMessage通知更新Scene

parent 4af542f5
......@@ -111,6 +111,14 @@ class Main extends egret.DisplayObjectContainer {
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') {
SceneManager.getInstance().roomScene.update(data)
}
})
platform.onSocketError((e) => {
console.error("onSocketError")
......
......@@ -2,9 +2,9 @@ class SceneManager extends egret.DisplayObjectContainer {
// 场景控制器的单例
private static instance: SceneManager;
// 开始场景
private roomScene: RoomScene;
public roomScene: RoomScene;
// 游戏场景
private gameScene: GameScene;
public gameScene: GameScene;
public constructor() {
super();
......@@ -15,7 +15,7 @@ class SceneManager extends egret.DisplayObjectContainer {
this.roomScene = new RoomScene();
this.gameScene = new GameScene();
// 默认添加开始场景
this.addChild(this.gameScene);
this.addChild(this.roomScene);
}
// 实例化单例获取方法
public static getInstance(): SceneManager {
......
......@@ -13,37 +13,20 @@ class RoomScene extends egret.Sprite {
console.log('RoomScene.init')
this.initBg()
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);
// 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() {
var shape: egret.Shape = new egret.Shape();
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