countdown.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. cc.Class({
  8. extends: cc.Component,
  9. properties: {
  10. time: cc.Label,
  11. countdown: 3,
  12. show:cc.Node,
  13. dialog:cc.Node,
  14. text:cc.Label,
  15. two:0,
  16. showTitle:"",
  17. startAudio: {
  18. default: null,
  19. type: cc.AudioClip
  20. },
  21. startFiveAudio: {
  22. default: null,
  23. type: cc.AudioClip
  24. },
  25. callback:null,
  26. start3Audio: {
  27. default: null,
  28. type: cc.AudioClip
  29. },
  30. start2Audio: {
  31. default: null,
  32. type: cc.AudioClip
  33. },
  34. start1Audio: {
  35. default: null,
  36. type: cc.AudioClip
  37. },
  38. start0Audio: {
  39. default: null,
  40. type: cc.AudioClip
  41. },
  42. },
  43. // LIFE-CYCLE CALLBACKS:
  44. // onLoad () {},
  45. start () {
  46. this.time.string = 3; // 场景文本框为 显示5
  47. this.countdown = 3;
  48. let audioId = cc.audioEngine.playEffect(this.start3Audio, false);
  49. cc.audioEngine.setVolume(audioId, 1);
  50. if (this.countdown > 0) {
  51. this.callback = this.schedule(function () { // 计时器将每隔 1s 执行一次。
  52. this.DoSomething();
  53. if(this.countdown==0){
  54. this.time.destroy();
  55. this.setElse()
  56. }
  57. }, 1);
  58. }
  59. // this.text.string = "起拍价5W" // 场景文本框为 显示5
  60. // this.countdown = 0;
  61. // if (this.countdown >= 0) {
  62. // }
  63. },
  64. setElse(){
  65. this.schedule(function () {
  66. // 计时器将每隔 1s 执行一次。
  67. this.textChane();
  68. }, 1)
  69. },
  70. DoSomething() {
  71. var audioId // 倒计时算法
  72. if (this.countdown >= 1) {
  73. this.countdown = this.countdown - 1;
  74. this.time.string = this.countdown;
  75. if(this.countdown == 2){
  76. audioId = cc.audioEngine.playEffect(this.start2Audio, false);
  77. cc.audioEngine.setVolume(audioId, 1);
  78. }else if(this.countdown == 1){
  79. audioId = cc.audioEngine.playEffect(this.start1Audio, false);
  80. cc.audioEngine.setVolume(audioId, 1);
  81. }else if(this.countdown == 0){
  82. audioId = cc.audioEngine.playEffect(this.start0Audio, false);
  83. cc.audioEngine.setVolume(audioId, 1);
  84. }
  85. //场景中文本框显示
  86. console.log(this.countdown,"set")
  87. }else{
  88. this.unschedule(this.callback)
  89. return
  90. }
  91. },
  92. textChane(){
  93. this.two = this.two + 1;
  94. console.log(this.two)
  95. if(this.two == 1){
  96. this.show.active = true
  97. let audioId = cc.audioEngine.playEffect(this.startFiveAudio, false);
  98. cc.audioEngine.setVolume(audioId, 1);
  99. }else if(this.two==3){
  100. this.text.string = '现在拍卖开始!';
  101. let audioId = cc.audioEngine.playEffect(this.startAudio, false);
  102. cc.audioEngine.setVolume(audioId, 1);
  103. }else if(this.two==4){
  104. this.node.destroy();
  105. this.show.active = false
  106. this.dialog.active = true
  107. }
  108. }
  109. // update (dt) {},
  110. });