GameOverRank.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. cc.Class({
  2. extends: cc.Component,
  3. name: "GameOverRank",
  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,isPlayer) {
  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. if (rank % 2 == 0) {
  19. this.backSprite.color = new cc.Color(55, 55, 55, 255);
  20. }
  21. if (isPlayer) {
  22. this.rankLabel.node.color = new cc.Color(0, 255, 0, 255);
  23. }
  24. this.rankLabel.string = (rank + 1).toString();
  25. this.createImage(avatarUrl);
  26. this.nickLabel.string = nick;
  27. this.topScoreLabel.string = grade.toString();
  28. },
  29. createImage(avatarUrl) {
  30. if (window.wx != undefined) {
  31. try {
  32. let image = wx.createImage();
  33. image.onload = () => {
  34. try {
  35. let texture = new cc.Texture2D();
  36. texture.initWithElement(image);
  37. texture.handleLoadedTexture();
  38. this.avatarImgSprite.spriteFrame = new cc.SpriteFrame(texture);
  39. } catch (e) {
  40. cc.log(e);
  41. this.avatarImgSprite.node.active = false;
  42. }
  43. };
  44. image.src = avatarUrl;
  45. }catch (e) {
  46. cc.log(e);
  47. this.avatarImgSprite.node.active = false;
  48. }
  49. } else {
  50. cc.loader.load({
  51. url: avatarUrl, type: 'jpg'
  52. }, (err, texture) => {
  53. this.avatarImgSprite.spriteFrame = new cc.SpriteFrame(texture);
  54. });
  55. }
  56. }
  57. });