Commit 81da815d by Mike Zhu

feat: init RoomScene

parent d3f5dd4b
......@@ -61,9 +61,12 @@ class Main extends egret.DisplayObjectContainer {
await this.loadResource()
var stage = egret.MainContext.instance.stage;
stage.setContentSize(1334, 750);
this.createGameScene();
await platform.login();
const userInfo = await platform.getUserInfo();
Store.onMessage({
type: 'setUserInfo',
data: userInfo
})
console.log(userInfo);
platform.connectSocket({
......@@ -85,19 +88,25 @@ class Main extends egret.DisplayObjectContainer {
platform.onSocketOpen(() => {
platform.sendSocketMessage({
data: JSON.stringify({
cid: "asnbduawh",
seq: "moving",
x: 100,
y: 123
type: 'entry',
rid: 'default_room',
payload: {
avatar_url: Store.getState().userInfo.avatarUrl,
nick_name: Store.getState().userInfo.nickName
}
}),
success: () => {
success: res => {
console.error("sendSocketMessage success")
},
fail: () => {
fail: res => {
console.error("sendSocketMessage fail")
},
complete: res => {
}
})
})
this.createGameScene();
platform.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data)
......
const _state = {}
let _state: any = {}
class Store {
static getState() {
return _state
......@@ -11,6 +11,8 @@ class Store {
}
break;
case 'setUserInfo':
_state.userInfo = message.data
default:
break;
}
......
class RoomScene extends egret.Sprite {
private startLabel: egret.TextField
private players: Array<any>
public constructor() {
super();
this.init()
......@@ -8,9 +11,68 @@ class RoomScene extends egret.Sprite {
// 初始化(给开始按钮绑定点击事件)
private 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
}
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() {
// 移除事件
}
......
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