ProgressBar.js 796 B

123456789101112131415161718192021222324252627282930313233
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. totalTime: {
  5. default: 10
  6. },
  7. },
  8. // ProgressBar.js
  9. onLoad () {
  10. },
  11. fire(time)
  12. {
  13. this.node.getComponent(cc.Sprite).fillRange = 1;
  14. this.totalTime = time;
  15. this.schedule(this.changeProgressBar, 1);
  16. },
  17. changeProgressBar () {
  18. this.node.getComponent(cc.Sprite).fillRange -= 1/this.totalTime;
  19. if (this.node.getComponent(cc.Sprite).fillRange <= 0) {
  20. this.unschedule(this.changeProgressBar);
  21. this.node.getComponent(cc.Sprite).fillRange = 0;
  22. }
  23. },
  24. setValue(value)
  25. {
  26. this.node.getComponent(cc.Sprite).fillRange = value;
  27. },
  28. stop()
  29. {
  30. this.unschedule(this.changeProgressBar);
  31. }
  32. });