bottomscoreitem.js 3.2 KB

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