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 {
private startLabel: egret.TextField
private players: Array<any>
private avatars: any
private rankGroup: any
public constructor() {
super();
......@@ -15,19 +15,33 @@ class GameoverScene extends egret.Sprite {
this.initBg()
this.initEndLabel()
this.initBackLabel()
// this.initRankGroup()
}
public update(data) {
const payload = data.payload
switch (data.type) {
case 'game_end':
this.updateRank(payload)
default:
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() {
var backLabel = new egret.TextField()
backLabel.text = '< 返回'
......@@ -61,18 +75,18 @@ class GameoverScene extends egret.Sprite {
})
SceneManager.getInstance().changeScene('roomScene')
}
private initCountDown(res) {
var cdText = new egret.TextField()
cdText.text = '10'
const timer = setInterval(() => {
if (cdText.text == '0') {
clearInterval(timer)
SceneManager.getInstance().changeScene('roomScene')
return
}
cdText.text = `${Number(cdText.text) - 1}`
}, 1000)
}
// private initCountDown(res) {
// var cdText = new egret.TextField()
// cdText.text = '10'
// const timer = setInterval(() => {
// if (cdText.text == '0') {
// clearInterval(timer)
// SceneManager.getInstance().changeScene('roomScene')
// return
// }
// cdText.text = `${Number(cdText.text) - 1}`
// }, 1000)
// }
private initBg() {
var shape: egret.Shape = new egret.Shape();
......
......@@ -49,10 +49,12 @@ class RoomScene extends egret.Sprite {
private updateStartLabelAndPlayers(payload) {
const {seat, members, nick_name} = payload
if (payload.seat == 0) {
this.startLabel.size = egret.TextField.default_size
this.startLabel.text = '开始'
this.startLabel.touchEnabled = true
this.startLabel.addEventListener(egret.TouchEvent.TOUCH_TAP, this.startHandler, this)
} else {
this.startLabel.size = egret.TextField.default_size
this.startLabel.text = '等待房主点击开始'
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