Head.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /** 头像设置 */
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class Head extends cc.Component {
  5. @property({ type: cc.Sprite, displayName: "头像" })
  6. img_head: cc.Sprite = null;
  7. @property({ type: cc.Label, displayName: '等级' })
  8. lbl_lv: cc.Label = null;
  9. private curLevel = 0;
  10. async start() {
  11. this.curLevel = gData.gameData.playerProp.gradeLevel;
  12. this.lbl_lv.string = 'Lv:' + this.curLevel.toString();
  13. this.initHead();
  14. }
  15. async initHead() {
  16. if (gData.wechatData.avatar != '') {
  17. let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
  18. if (result) {
  19. this.img_head.spriteFrame = new cc.SpriteFrame(result);
  20. }
  21. }
  22. }
  23. protected update(dt: number): void {
  24. if (gData.gameData.init_head) {
  25. this.initHead();
  26. }
  27. if (this.curLevel != gData.gameData.playerProp.gradeLevel) {
  28. this.curLevel = gData.gameData.playerProp.gradeLevel;
  29. this.lbl_lv.string = 'Lv:' + this.curLevel.toString();
  30. }
  31. }
  32. clickHead() {
  33. mk.ui.openPanel('module/setting/setting');
  34. }
  35. }