bottomscoreitem.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var Sprite = require('./libs/sprite.js').Sprite
  2. var Label = require('./libs/label.js').Label
  3. function BottomScoreItem(x, y, width, height) {
  4. this.x = x;
  5. this.y = y;
  6. this.width = width;
  7. this.height = height;
  8. }
  9. var circlebg = "openDataContext/asset/circle.png";
  10. BottomScoreItem.prototype.create = function() {
  11. // this.rankbg = new Sprite("openDataContext/asset/paiwei_xin_1_6_6.png", this.x - 50, this.y + this.height * 0.5 * 0.1, 720, 300);
  12. // this.rankbg.parent = this;
  13. let labelOffset = 65;
  14. let labelStyle = "#ffffff";
  15. let fontSize = "35px";
  16. this.rankLabel = new Label(this.x+90 , this.y-315 );
  17. this.rankLabel.fontSize = "65px";
  18. this.rankLabel.fillStyle = labelStyle;
  19. this.rankLabel.textAlign = 'center';
  20. let rankWidth = 67;
  21. let rankHeight = 63;
  22. //this.rankimg = new Sprite('', this.x + 20, this.y + this.height * 0.5 - rankHeight * 0.5, rankWidth, rankHeight);
  23. let offsetX = 90;
  24. // let circleWidth = 96;
  25. // let circleHeight = 96;
  26. // this.circleicon = new Sprite(circlebg, this.x + offsetX, this.y + this.height * 0.5 - circleHeight * 0.5, circleWidth, circleHeight);
  27. // this.circleicon.visible = false;
  28. let iconWidth = 60;
  29. let iconHeight = 60;
  30. this.icon = new Sprite('', this.x + 120, this.y -365/**+ this.height * 0.5 - iconHeight * 0.5 + 20*/, iconWidth, iconHeight);
  31. this.nameLabel = new Label(this.x + 220, this.y - 320);
  32. this.nameLabel.fontSize = fontSize;
  33. this.nameLabel.fillStyle = labelStyle;
  34. this.scoreNum = new Label(this.x + this.width - 170, this.y - 320);
  35. this.scoreNum.fontSize = fontSize;
  36. this.scoreNum.fillStyle = labelStyle;
  37. this.scoreNum.textAlign = "center";
  38. this.scoreLabel = new Label(this.x + this.width - 100, this.y - 320);
  39. this.scoreLabel.fontSize = fontSize;
  40. this.scoreLabel.fillStyle = labelStyle;
  41. this.scoreLabel.textAlign = "right";
  42. }
  43. BottomScoreItem.prototype.setData = function(rankNum,name, iconUrl, score) {
  44. this.icon.src = iconUrl;
  45. this.nameLabel.text = name;
  46. this.scoreNum.text = score;
  47. this.scoreLabel.text ="第 关";
  48. this.rankLabel.text = rankNum;
  49. if (rankNum <= 3) {
  50. //this.rankLabel.visible = false;
  51. //this.rankimg.visible = true;
  52. //this.rankimg.src = this.getRankUrl(rankNum);
  53. } else {
  54. //this.rankLabel.visible = true;
  55. //this.rankimg.visible = false;
  56. //this.rankLabel.text = rankNum;
  57. }
  58. }
  59. // var rank1url = "openDataContext/asset/paihang-1-3.png";
  60. // var rank2url = "openDataContext/asset/paihang-1-3-2.png";
  61. // var rank3url = "openDataContext/asset/paihang-1-3-1.png";
  62. // BottomScoreItem.prototype.getRankUrl = function(num) {
  63. // let rankNum = num;
  64. // let url = "";
  65. // switch (rankNum) {
  66. // case 1:
  67. // url = rank1url;
  68. // break;
  69. // case 2:
  70. // url = rank2url;
  71. // break;
  72. // case 3:
  73. // url = rank3url;
  74. // break;
  75. // default:
  76. // url = "";
  77. // break;
  78. // }
  79. // return url;
  80. // }
  81. BottomScoreItem.prototype.drawToCanvas = function(ctx) {
  82. //this.rankbg.drawToCanvas(ctx);
  83. this.scoreNum.drawToCanvas(ctx);
  84. this.rankLabel.drawToCanvas(ctx);
  85. this.icon.drawToCanvas(ctx);
  86. this.nameLabel.drawToCanvas(ctx);
  87. this.scoreLabel.drawToCanvas(ctx);
  88. }
  89. module.exports.BottomScoreItem = BottomScoreItem;