slider_progress.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. progressValue: 0
  14. },
  15. // LIFE-CYCLE CALLBACKS:
  16. onLoad() {
  17. this.slider = this.getComponent(cc.Slider);
  18. this.progressbar = this.getComponent(cc.ProgressBar);
  19. // console.log("slider");
  20. if (this.slider)
  21. this.slider.progress = this.progressValue;
  22. if (this.progressbar)
  23. this.progressbar.progress = this.progressValue;
  24. if (this.slider == null || this.progressbar == null) {
  25. return;
  26. }
  27. this.progressbar.progress = this.slider.progress;
  28. let self = this;
  29. this.slider.node.on('slide', function (event) {
  30. this.progressbar.progress = this.slider.progress;
  31. }, this);
  32. },
  33. start() {
  34. },
  35. onSetProcgress(value) {
  36. this.progressValue = value;
  37. if (this.slider)
  38. this.slider.progress = value;
  39. if (this.progressbar)
  40. this.progressbar.progress = value;
  41. // console.log("slider", value);
  42. }
  43. // update (dt) {},
  44. });