GameUIState.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. SpeedLabel: {
  14. default: null,
  15. type: cc.Label,
  16. },
  17. Perfect: {
  18. default: null,
  19. type: cc.Node,
  20. },
  21. //跳远 扔标枪 的计数板
  22. UIDistanceNum: {
  23. default: null,
  24. type: cc.Node
  25. },
  26. //显示分数
  27. UIScore: {
  28. default: null,
  29. type: cc.Label
  30. },
  31. //游戏结束ui
  32. GameOverUIScore: {
  33. default: null,
  34. type: cc.Label
  35. }
  36. },
  37. // LIFE-CYCLE CALLBACKS:
  38. onLoad() {
  39. this.PerfectAnimation = this.Perfect.getComponent(cc.Animation);
  40. this.DistanceLabel = this.UIDistanceNum.getComponent(cc.Label);
  41. this.distance = 0;
  42. this.distanceCount = 0;
  43. this.timer = 0;
  44. },
  45. start() {
  46. },
  47. update(dt) {
  48. this.SpeedLabel.string = GlobalData.game.GameSpeed.toFixed(2);
  49. if (this.isFinish) {
  50. this.onComputUIDistance(dt);
  51. }
  52. if (this.UIScore) {
  53. this.UIScore.string = GlobalData.game.GameScore;
  54. }
  55. if (this.GameOverUIScore && this.GameOverUIScore.node.parent.parent.active) {
  56. this.GameOverUIScore.string = GlobalData.game.GameScore;
  57. }
  58. },
  59. //完美提示
  60. OnPayPerfectAnimation() {
  61. this.PerfectAnimation.play();
  62. },
  63. //显示当前跳远和标枪的距离UI
  64. onStartShowUIDistance(InputDistance, InputTime) {
  65. this.DistanceLabel.node.parent.active = true;
  66. this.distance = 0;
  67. this.distanceCount = InputDistance;
  68. this.timer = InputTime;
  69. this.isFinish = true;
  70. this.DistanceLabel.string = "0.00M";
  71. // console.log('CSpeed1=', this.distanceCount, InputDistance, InputTime,this.timer);
  72. },
  73. //计算当前UI距离
  74. onComputUIDistance(dt) {
  75. var ADistance = this.distanceCount;
  76. var CDistance = this.distance;
  77. var speedFactor = (ADistance - CDistance) * 0.05;
  78. CDistance += speedFactor;
  79. this.timer -= dt;//timer =0.3
  80. // console.log(this.timer);
  81. if (this.timer <= 0 && CDistance - ADistance >= -0.1) {
  82. this.isFinish = false;
  83. CDistance = ADistance;
  84. setTimeout(() => {
  85. this.DistanceLabel.node.parent.active = false;
  86. }, 1500);
  87. }
  88. this.distance = CDistance;
  89. // console.log('CSpeed2=', CDistance, ADistance);
  90. this.DistanceLabel.string = CDistance.toFixed(2) + "M";
  91. },
  92. });