TopBar.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class TopBar extends cc.Component {
  4. @property({type:cc.SpriteFrame})
  5. genderBoy:cc.SpriteFrame = null;
  6. @property({type:cc.SpriteFrame})
  7. genderGirl:cc.SpriteFrame = null;
  8. @property({type:cc.Label})
  9. timeLabel:cc.Label = null;
  10. @property({type:cc.Sprite})
  11. selfAvatar:cc.Sprite = null;
  12. @property({type:cc.Sprite})
  13. selfGender:cc.Sprite = null;
  14. @property({type:cc.Sprite})
  15. otherAvatar:cc.Sprite = null;
  16. @property({type:cc.Sprite})
  17. otherGender:cc.Sprite = null;
  18. time_init: number = undefined;
  19. onLoad(){
  20. window.topBar = this;
  21. this.node.getChildByName("Self").x = -cc.winSize.width/2 + 110;
  22. this.node.getChildByName("Other").x = cc.winSize.width/2 - 90;
  23. this.hide();
  24. }
  25. hide(){
  26. this.node.children.forEach((child)=>{
  27. child.active = false;
  28. });
  29. }
  30. show(){
  31. this.node.children.forEach((child)=>{
  32. child.active = true;
  33. });
  34. if(window.myPlayerInfo.gender==2){
  35. this.selfGender.spriteFrame = this.genderGirl;
  36. }else{
  37. this.selfGender.spriteFrame = this.genderBoy;
  38. }
  39. this.selfAvatar.spriteFrame = window.myPlayerInfo.avatar;
  40. if(window.otherPlayerInfo.gender==2){
  41. this.otherGender.spriteFrame = this.genderGirl;
  42. }else{
  43. this.otherGender.spriteFrame = this.genderBoy;
  44. }
  45. this.otherAvatar.spriteFrame = window.otherPlayerInfo.avatar;
  46. }
  47. updateTime(time:number){
  48. if (this.time_init === undefined) {
  49. this.time_init = time;
  50. }
  51. this.timeLabel.string = time.toString();
  52. }
  53. }