RankItem.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. cc.Class({
  2. extends: cc.Component,
  3. name: "RankItem",
  4. properties: {
  5. backSprite: cc.Node,
  6. rankLabel: cc.Label,
  7. avatarImgSprite: cc.Sprite,
  8. nickLabel: cc.Label,
  9. topScoreLabel: cc.Label,
  10. },
  11. start() {
  12. },
  13. init: function (rank, data) {
  14. let avatarUrl = data.avatarUrl;
  15. // let nick = data.nickname.length <= 10 ? data.nickname : data.nickname.substr(0, 10) + "...";
  16. let nick = data.nickname;
  17. let grade = data.KVDataList.length != 0 ? data.KVDataList[0].value : 0;
  18. this.rankLabel.string = (rank + 1).toString();
  19. this.createImage(avatarUrl);
  20. this.nickLabel.string = nick;
  21. this.topScoreLabel.string = grade.toString();
  22. },
  23. createImage(avatarUrl) {
  24. try {
  25. let image = wx.createImage();
  26. image.onload = () => {
  27. try {
  28. let texture = new cc.Texture2D();
  29. texture.initWithElement(image);
  30. texture.handleLoadedTexture();
  31. this.avatarImgSprite.spriteFrame = new cc.SpriteFrame(texture);
  32. } catch (e) {
  33. cc.log(e);
  34. this.avatarImgSprite.node.active = false;
  35. }
  36. };
  37. image.src = avatarUrl;
  38. }catch (e) {
  39. cc.log(e);
  40. this.avatarImgSprite.node.active = false;
  41. }
  42. }
  43. });