const {ccclass, property} = cc._decorator; @ccclass export default class TopBar extends cc.Component { @property({type:cc.SpriteFrame}) genderBoy:cc.SpriteFrame = null; @property({type:cc.SpriteFrame}) genderGirl:cc.SpriteFrame = null; @property({type:cc.Label}) timeLabel:cc.Label = null; @property({type:cc.Sprite}) selfAvatar:cc.Sprite = null; @property({type:cc.Sprite}) selfGender:cc.Sprite = null; @property({type:cc.Sprite}) otherAvatar:cc.Sprite = null; @property({type:cc.Sprite}) otherGender:cc.Sprite = null; time_init: number = undefined; onLoad(){ window.topBar = this; this.node.getChildByName("Self").x = -cc.winSize.width/2 + 110; this.node.getChildByName("Other").x = cc.winSize.width/2 - 90; this.hide(); } hide(){ this.node.children.forEach((child)=>{ child.active = false; }); } show(){ this.node.children.forEach((child)=>{ child.active = true; }); if(window.myPlayerInfo.gender==2){ this.selfGender.spriteFrame = this.genderGirl; }else{ this.selfGender.spriteFrame = this.genderBoy; } this.selfAvatar.spriteFrame = window.myPlayerInfo.avatar; if(window.otherPlayerInfo.gender==2){ this.otherGender.spriteFrame = this.genderGirl; }else{ this.otherGender.spriteFrame = this.genderBoy; } this.otherAvatar.spriteFrame = window.otherPlayerInfo.avatar; } updateTime(time:number){ if (this.time_init === undefined) { this.time_init = time; } this.timeLabel.string = time.toString(); } }