LoadScene.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class LoadScene extends cc.Component {
  10. //开始按钮
  11. @property(cc.Node)
  12. StartGameNode: cc.Node = null
  13. //开始按钮
  14. @property(cc.ProgressBar)
  15. progress: cc.ProgressBar = null
  16. progressNum: number = null
  17. @property(cc.Label)
  18. launchDesc: cc.Label = null
  19. start() {
  20. this.StartGameNode.active = false
  21. this.LoadBundle('sub').then((e) => {
  22. cc.director.preloadScene("Hall", (curcomplete, totalcount) => {
  23. this.progress.progress = (((curcomplete / totalcount) / 2) + 0.5)
  24. this.updatelaunchDesc()
  25. }, () => {
  26. this.StartGameNode.active = true
  27. })
  28. })
  29. }
  30. protected update(dt: number): void {
  31. if (this.progress.progress < 0.5) {
  32. this.progress.progress += 0.02
  33. this.updatelaunchDesc()
  34. }
  35. }
  36. updatelaunchDesc() {
  37. this.launchDesc.string = `${(this.progress.progress * 100).toFixed(0)}%`;
  38. }
  39. StartGame() {
  40. console.error('Hall');
  41. cc.director.loadScene("Hall")
  42. }
  43. LoadBundle(path: string): Promise<cc.AssetManager.Bundle> {
  44. return new Promise((resolve, reject) => {
  45. cc.assetManager.loadBundle(path, (err, bundle) => {
  46. if (err) {
  47. console.log('加载Bundle失败')
  48. reject(err)
  49. return;
  50. }
  51. resolve(bundle)
  52. });
  53. })
  54. }
  55. }