CachetaTimePointer.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. const Global = require("Global");
  2. var SoundFun = require("CachetaSoundFun");
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. _countdown:0,
  7. _totalTime:0,
  8. },
  9. onLoad: function()
  10. {
  11. this.node.getChildByName("TimeSprite").getComponent(cc.Sprite).fillRange = 1
  12. this.node.active = false;
  13. },
  14. getNowTimeColor(times) {
  15. if(times <= 6) {
  16. return new cc.color(255, 30, 0);
  17. }else if(times <= 9) {
  18. return new cc.color(255, 144, 0);
  19. }else if(times <= 12) {
  20. return new cc.color(230, 255, 0);
  21. }else{
  22. return new cc.color(0, 255, 31);
  23. }
  24. },
  25. stopTimeSchedule: function(show)
  26. {
  27. // var SystemLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("SystemTimeLabel").getComponent(cc.Label);
  28. // SystemLeftTimeLabel.string = 0;//系统时间
  29. // var UserLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("UserTimeLabel").getComponent(cc.Label);
  30. // UserLeftTimeLabel.string = 0;//玩家时间
  31. if (this.timeCallback != null)
  32. {
  33. this.unschedule(this.timeCallback);
  34. this.timeCallback = null;
  35. }
  36. if(show){
  37. this.node.active = true;
  38. }else{
  39. this.node.active = false;
  40. }
  41. },
  42. playTimeAction: function(SystemLeftTime,UserLeftTime, bSelf)
  43. {
  44. this.node.active = true;
  45. this._usedUserTime = false;
  46. this._countdown = UserLeftTime.toFixed(1);
  47. this._waitTime = 0;
  48. this._totalTime = SystemLeftTime;
  49. // var UserLeftTimeLabel = this.node.getChildByName("TimeLabelNode").getChildByName("UserTimeLabel").getComponent(cc.Label);
  50. // UserLeftTimeLabel.string = Math.floor(UserLeftTime).toString();//玩家时间
  51. let aniNode = this.node.getChildByName("ani");
  52. aniNode.angle = UserLeftTime/SystemLeftTime*360;
  53. let spNode = this.node.getChildByName("TimeSprite");
  54. spNode.color = this.getNowTimeColor(this._countdown);
  55. var self = this
  56. this.timeCallback = function()
  57. {
  58. self._waitTime = self._waitTime+0.1;
  59. if(self._countdown <= 0){
  60. self.stopTimeSchedule(true);
  61. return;
  62. }
  63. self._countdown = self._countdown-0.1;
  64. if(self._countdown < 0){
  65. self._countdown = 0;
  66. }
  67. spNode.color = self.getNowTimeColor(self._countdown);
  68. aniNode.angle = self._countdown/SystemLeftTime*360;
  69. if(Math.abs(self._countdown - 5.5) <= 1e-7 && bSelf) {
  70. Global.print("bofang5")
  71. SoundFun.playEffectEX("time");
  72. }
  73. if(Math.abs(self._countdown - 3.5) <= 1e-7 && bSelf) {
  74. Global.print("bofang3")
  75. SoundFun.playEffectEX("time");
  76. }
  77. if(Math.abs(self._countdown - 1.5) <= 1e-7 && bSelf) {
  78. Global.print("bofang1")
  79. SoundFun.playEffectEX("time");
  80. }
  81. // if(!self._usedUserTime){//还没有使用玩家时间
  82. // SystemLeftTimeLabel.string = parseInt(self._countdown);
  83. // self._totalTime = 30;
  84. // }else{//已经开始使用玩家时间
  85. // SystemLeftTimeLabel.string = parseInt(self._countdown);
  86. // self._totalTime = 30;
  87. // }
  88. // UserLeftTimeLabel.string = parseInt(self._countdown);
  89. if(self._countdown/self._totalTime >= 0){
  90. self.node.getChildByName("TimeSprite").getComponent(cc.Sprite).fillRange = self._countdown/self._totalTime;
  91. }
  92. }
  93. this.unschedule(this.timeCallback);
  94. this.schedule(this.timeCallback,0.1);
  95. },
  96. start () {
  97. },
  98. });