TrucoTimePointer.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const Global = require("Global");
  2. var SoundFun = require("TrucoSoundFun");
  3. cc.Class({
  4. extends: cc.Component,
  5. properties: {
  6. _countdown:0,
  7. _totalTime:0,
  8. },
  9. onLoad: function(){
  10. this.node.active = false;
  11. },
  12. getNowTimeColor(times) {
  13. if(times <= 6) {
  14. return new cc.color(255, 30, 0);
  15. }else if(times <= 9) {
  16. return new cc.color(255, 144, 0);
  17. }else if(times <= 12) {
  18. return new cc.color(230, 255, 0);
  19. }else{
  20. return new cc.color(0, 255, 31);
  21. }
  22. },
  23. stopTimeSchedule: function(show){
  24. if (this.timeCallback != null)
  25. {
  26. this.unschedule(this.timeCallback);
  27. this.timeCallback = null;
  28. }
  29. if(show){
  30. this.node.active = true;
  31. }else{
  32. this.node.active = false;
  33. }
  34. },
  35. playTimeAction: function(UserLeftTime, bSelf){
  36. this.node.active = true;
  37. this._countdown = UserLeftTime;
  38. let timeLabel = this.node.getChildByName("TimeSprite").getChildByName("time").getComponent(cc.Label);
  39. timeLabel.string = this._countdown;
  40. var self = this
  41. this.timeCallback = function(){
  42. if(self._countdown <= 0){
  43. self.stopTimeSchedule(false);
  44. return;
  45. }
  46. self._countdown--;
  47. if(self._countdown < 0){
  48. self._countdown = 0;
  49. }
  50. if(self._countdown <= 5) {
  51. SoundFun.playEffectEX(SoundFun.EX_COUNTDOWN);
  52. }
  53. timeLabel.string = self._countdown;
  54. }
  55. this.unschedule(this.timeCallback);
  56. this.schedule(this.timeCallback,1);
  57. },
  58. start () {
  59. },
  60. });