Commit 1f4ef36c by Mike Zhu

更新游戏排行

parent 942afd4d
class Rank extends egret.Sprite {
public constructor(userData) {
super()
this.init(userData)
}
private avatar = new egret.Bitmap()
private bg = new egret.Bitmap()
private imageLoader = new egret.ImageLoader()
private init(userData) {
this.bg.width = 100
this.bg.height = 100
this.bg.texture = RES.getRes("avatar_bg_jpg")
this.addChild(this.bg)
this.avatar.x = 10
this.avatar.y = 10
this.avatar.width = 80
this.avatar.height = 80
this.imageLoader.addEventListener(egret.Event.COMPLETE,this.loadCompleteHandler,this)
this.imageLoader.load(userData.avatar_url || "http://www.insajderi.com/wp-content/uploads/2018/01/asdja.jpg")
this.addChild(this.avatar)
}
private loadCompleteHandler() {
let texture = new egret.Texture()
texture._setBitmapData(this.imageLoader.data)
this.avatar.texture = texture
}
}
class RankGroup extends egret.Sprite {
public constructor(ranks) {
super()
this.init(ranks)
}
private init(ranks) {
ranks.forEach((rank, index) => {
let yPosition = index * 100
let avatar = new Avatar(rank[0])
avatar.y = yPosition
this.addChild(avatar)
let name = new egret.TextField()
name.text = rank[0].nick_name
name.y = yPosition + 40
name.x = 120
this.addChild(name)
let score = new egret.TextField()
score.text = rank[1]
score.y = yPosition + 40
score.x = 500
this.addChild(score)
})
}
}
\ No newline at end of file
class GameoverScene extends egret.Sprite { class GameoverScene extends egret.Sprite {
private startLabel: egret.TextField private startLabel: egret.TextField
private players: Array<any> private rankGroup: any
private avatars: any
public constructor() { public constructor() {
super(); super();
...@@ -15,19 +15,33 @@ class GameoverScene extends egret.Sprite { ...@@ -15,19 +15,33 @@ class GameoverScene extends egret.Sprite {
this.initBg() this.initBg()
this.initEndLabel() this.initEndLabel()
this.initBackLabel() this.initBackLabel()
// this.initRankGroup()
} }
public update(data) { public update(data) {
const payload = data.payload const payload = data.payload
switch (data.type) { switch (data.type) {
case 'game_end': case 'game_end':
this.updateRank(payload)
default: default:
break; break;
} }
} }
private updateRank(data) {
if (this.rankGroup && this.rankGroup.parent) {
this.rankGroup.parent.removeChild(this.rankGroup)
}
this.rankGroup = new RankGroup(data.rank)
this.rankGroup.x = 400
this.rankGroup.y = 250
this.addChild(this.rankGroup)
}
// private initRankGroup() {
// this.rankGroup
// }
private initBackLabel() { private initBackLabel() {
var backLabel = new egret.TextField() var backLabel = new egret.TextField()
backLabel.text = '< 返回' backLabel.text = '< 返回'
...@@ -61,18 +75,18 @@ class GameoverScene extends egret.Sprite { ...@@ -61,18 +75,18 @@ class GameoverScene extends egret.Sprite {
}) })
SceneManager.getInstance().changeScene('roomScene') SceneManager.getInstance().changeScene('roomScene')
} }
private initCountDown(res) { // private initCountDown(res) {
var cdText = new egret.TextField() // var cdText = new egret.TextField()
cdText.text = '10' // cdText.text = '10'
const timer = setInterval(() => { // const timer = setInterval(() => {
if (cdText.text == '0') { // if (cdText.text == '0') {
clearInterval(timer) // clearInterval(timer)
SceneManager.getInstance().changeScene('roomScene') // SceneManager.getInstance().changeScene('roomScene')
return // return
} // }
cdText.text = `${Number(cdText.text) - 1}` // cdText.text = `${Number(cdText.text) - 1}`
}, 1000) // }, 1000)
} // }
private initBg() { private initBg() {
var shape: egret.Shape = new egret.Shape(); var shape: egret.Shape = new egret.Shape();
......
...@@ -49,10 +49,12 @@ class RoomScene extends egret.Sprite { ...@@ -49,10 +49,12 @@ class RoomScene extends egret.Sprite {
private updateStartLabelAndPlayers(payload) { private updateStartLabelAndPlayers(payload) {
const {seat, members, nick_name} = payload const {seat, members, nick_name} = payload
if (payload.seat == 0) { if (payload.seat == 0) {
this.startLabel.size = egret.TextField.default_size
this.startLabel.text = '开始' this.startLabel.text = '开始'
this.startLabel.touchEnabled = true this.startLabel.touchEnabled = true
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this) this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
} else { } else {
this.startLabel.size = egret.TextField.default_size
this.startLabel.text = '等待房主点击开始' this.startLabel.text = '等待房主点击开始'
this.startLabel.touchEnabled = false this.startLabel.touchEnabled = false
} }
......
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