ChangeTimeAndProgressBar.js 904 B

123456789101112131415161718192021222324252627282930313233
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. ProgressBar: {
  5. default: null,
  6. type: cc.Node,
  7. serializable: true,
  8. }
  9. },
  10. SetProgressBar(RemainTime,TotalTime)
  11. {
  12. this.node.getComponent(cc.Label).string = this.CastSecondsToHours(RemainTime);
  13. this.ProgressBar.getComponent(cc.ProgressBar).progress = RemainTime/TotalTime;
  14. },
  15. CastSecondsToHours(Time)
  16. {
  17. if(Time<60) return Math.floor(Time)+'秒';
  18. if(Time<3600 && Time >=60)
  19. {
  20. return Math.floor(Time/60)+'分'+Math.floor(Time%60)+'秒';
  21. }
  22. if(Time>=3600)
  23. {
  24. let Hour = Math.floor(Time/3600);
  25. let s = Time%3600;
  26. let Min = Math.floor(s/60);
  27. return Math.floor(Hour)+'小时'+Math.floor(Min)+'分';
  28. }
  29. return Math.floor(Time/3600);
  30. },
  31. });