1
0

HotUpdate.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. // manifestUrl: cc.RawAsset,
  5. preloadProgress: cc.ProgressBar,
  6. preloadLabel: cc.Label,
  7. updateUI: cc.Node,
  8. _updating: false, //是否正在更新
  9. _canRetry: false, //能否重新获取更新
  10. _preloaded: false, //是否已经预加载完资源
  11. },
  12. onLoad () {
  13. },
  14. init () {
  15. if(cc.sys.platform === cc.sys.WECHAT_GAME) {
  16. this.updateUI.active = true;
  17. let dis = 0.012
  18. this.timeCtrl = () => {
  19. if(parseInt(this.preloadProgress.progress) == 1) {
  20. this._preloaded = true;
  21. this.unschedule(this.timeCtrl)
  22. } else {
  23. dis = dis < 0.002 ? 0.002 : dis - 0.0001;
  24. this.preloadProgress.progress += dis
  25. }
  26. this.preloadLabel.string = '加载中,请稍候...' + (this.preloadProgress.progress * 100).toFixed(0) + '%'
  27. }
  28. this.schedule(this.timeCtrl, 0.03)
  29. } else {
  30. this.updateUI.active = false;
  31. }
  32. },
  33. /**
  34. * 预加载结束
  35. */
  36. endPreload () {
  37. this.preloadProgress.progress = 1;
  38. this.scheduleOnce(() => {
  39. this.updateUI.active = false;
  40. }, 0.5)
  41. },
  42. onDestroy () {
  43. },
  44. start () {
  45. },
  46. // update (dt) {},
  47. });