ComboDisplay.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. labelCombo: cc.Label,
  5. anim: cc.Animation,
  6. comboColors: [cc.Color],
  7. showDuration: 0,
  8. comboActive: false
  9. },
  10. init (inGameUI) {
  11. this.inGameUI = inGameUI;
  12. this.comboCount = 0;
  13. this.node.active = false;
  14. this.showTimer = 0;
  15. this.comboScore = 1;
  16. },
  17. playCombo () {
  18. if(this.comboScore == 5) {
  19. this.comboCount++;
  20. this.node.active = true;
  21. // this.unschedule(this.hide);
  22. // let colorIdx = Math.min(Math.floor(this.comboCount / 10), this.comboColors.length - 1);
  23. // this.labelCombo.node.color = this.comboColors[colorIdx];
  24. this.labelCombo.string = this.comboCount;
  25. this.anim.play('combo-pop');
  26. this.showTimer = 0;
  27. this.comboActive = true;
  28. this.inGameUI.changeScoreRatio('combo');
  29. // this.scheduleOnce(this.hide.bind(this), this.showDuration );
  30. } else {
  31. this.comboScore++
  32. }
  33. },
  34. hide () {
  35. this.comboCount = 0;
  36. this.node.active = false;
  37. },
  38. update (dt) {
  39. if (!this.node.active) {
  40. return;
  41. }
  42. this.showTimer += dt;
  43. if (this.showTimer >= this.showDuration) {
  44. this.hide();
  45. this.comboActive = false;
  46. this.node.active = false;
  47. this.comboScore = 1;
  48. this.inGameUI.endScoreRatio('combo');
  49. }
  50. }
  51. });