Level_Time.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. Time:90,
  5. intervalTime:90,
  6. progressbar:null,
  7. progress:1,
  8. Success:cc.Node,
  9. GameOver:cc.Node,
  10. Store:cc.Node,
  11. },
  12. onLoad: function () {
  13. Audio.playmusic('resources/audio/music_bg.mp3');
  14. },
  15. // use this for initialization
  16. //cc.director.pause()
  17. //cc.director.resume()
  18. start: function () {
  19. //this.Time = Global.LevelTime;
  20. //this.intervalTime =Global.LevelTime;
  21. this.progressbar = cc.find('Canvas/ProgressBar');
  22. this.progress = this.progressbar.getComponent(cc.ProgressBar);
  23. },
  24. // called every frame
  25. update: function (dt) {
  26. if(this.Success.active == true){
  27. return;
  28. }
  29. if(this.Store.active == true){
  30. return;
  31. }
  32. if (this.intervalTime >= 0 ) {
  33. this.intervalTime -= dt;
  34. this.progress.progress =this.intervalTime/this.Time;
  35. }else{
  36. //console.log('游戏结束');
  37. //cc.director.pause();
  38. if(this.GameOver.active == false){
  39. cc.audioEngine.stopMusic();
  40. Audio.playeffect('resources/audio/sound_lose.ogg');
  41. }
  42. this.GameOver.active = true;
  43. }
  44. },
  45. });