CountDown.js 937 B

123456789101112131415161718192021222324252627282930313233343536
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. countDown(callback)
  6. {
  7. this.node.opacity = 255;
  8. this.callback = callback;
  9. this.currentCount = 3;
  10. this.counting();
  11. },
  12. counting()
  13. {
  14. let Self = this;
  15. cc.loader.loadRes("Audios/Game/Nums/"+this.currentCount, cc.AudioClip, (err, audioClip)=> {
  16. Self.node.getComponent(cc.Label).string = Self.currentCount;
  17. Self.currentAudio = cc.audioEngine.play(audioClip, false, 1);
  18. cc.audioEngine.setFinishCallback(Self.currentAudio, function () {
  19. if(Self.currentCount == 1)
  20. {
  21. Self.currentCount = 3;
  22. Self.node.opacity = 0;
  23. Self.callback();
  24. return;
  25. }
  26. Self.currentCount--;
  27. Self.counting();
  28. });
  29. });
  30. }
  31. });