Commit 81da815d by Mike Zhu

feat: init RoomScene

parent d3f5dd4b
...@@ -61,9 +61,12 @@ class Main extends egret.DisplayObjectContainer { ...@@ -61,9 +61,12 @@ class Main extends egret.DisplayObjectContainer {
await this.loadResource() await this.loadResource()
var stage = egret.MainContext.instance.stage; var stage = egret.MainContext.instance.stage;
stage.setContentSize(1334, 750); stage.setContentSize(1334, 750);
this.createGameScene();
await platform.login(); await platform.login();
const userInfo = await platform.getUserInfo(); const userInfo = await platform.getUserInfo();
Store.onMessage({
type: 'setUserInfo',
data: userInfo
})
console.log(userInfo); console.log(userInfo);
platform.connectSocket({ platform.connectSocket({
...@@ -85,19 +88,25 @@ class Main extends egret.DisplayObjectContainer { ...@@ -85,19 +88,25 @@ class Main extends egret.DisplayObjectContainer {
platform.onSocketOpen(() => { platform.onSocketOpen(() => {
platform.sendSocketMessage({ platform.sendSocketMessage({
data: JSON.stringify({ data: JSON.stringify({
cid: "asnbduawh", type: 'entry',
seq: "moving", rid: 'default_room',
x: 100, payload: {
y: 123 avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}), }),
success: () => { success: res => {
console.error("sendSocketMessage success") console.error("sendSocketMessage success")
}, },
fail: () => { fail: res => {
console.error("sendSocketMessage fail") console.error("sendSocketMessage fail")
},
complete: res => {
} }
}) })
}) })
this.createGameScene();
platform.onSocketMessage(function(res) { platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data) console.log('收到服务器内容:' + res.data)
......
const _state = {} let _state: any = {}
class Store { class Store {
static getState() { static getState() {
return _state return _state
...@@ -11,6 +11,8 @@ class Store { ...@@ -11,6 +11,8 @@ class Store {
} }
break; break;
case 'setUserInfo':
_state.userInfo = message.data
default: default:
break; break;
} }
......
class RoomScene extends egret.Sprite { class RoomScene extends egret.Sprite {
private startLabel: egret.TextField
private players: Array<any>
public constructor() { public constructor() {
super(); super();
this.init() this.init()
...@@ -8,9 +11,68 @@ class RoomScene extends egret.Sprite { ...@@ -8,9 +11,68 @@ class RoomScene extends egret.Sprite {
// 初始化(给开始按钮绑定点击事件) // 初始化(给开始按钮绑定点击事件)
private init() { private init() {
console.log('RoomScene.init') 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 // put display object to this scene
} }
private initBg() {
var shape: egret.Shape = new egret.Shape();
shape.graphics.beginFill(0x343E5F);
shape.graphics.drawRect(0, 0, 2000, 2000);
shape.graphics.endFill();
this.addChild(shape);
var bg: egret.Bitmap = new egret.Bitmap()
bg.texture = RES.getRes("logo_jpg")
bg.scaleX = bg.scaleY = 2
bg.x = 1334 / 2 - 280
bg.y = 100
this.addChild(bg)
}
private initStartLabel() {
this.startLabel = new egret.TextField()
this.startLabel.textColor = 0xF0D66D
this.startLabel.text = "请稍等..."
this.startLabel.width = 200
this.startLabel.anchorOffsetX = 100
this.startLabel.x = 1334 / 2
this.startLabel.textAlign = egret.HorizontalAlign.CENTER;
this.startLabel.y = 1136 / 2
}
private startHandler() {
console.log('starthandler')
SceneManager.getInstance().changeScene('gameScene');
}
public release() { public release() {
// 移除事件 // 移除事件
} }
......
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