1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- // Learn TypeScript:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
- // Learn Attribute:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
- // Learn life-cycle callbacks:
- // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class LoadScene extends cc.Component {
- //开始按钮
- @property(cc.Node)
- StartGameNode: cc.Node = null
- //开始按钮
- @property(cc.ProgressBar)
- progress: cc.ProgressBar = null
- progressNum: number = null
- @property(cc.Label)
- launchDesc: cc.Label = null
- start() {
- this.StartGameNode.active = false
- this.LoadBundle('sub').then((e) => {
- cc.director.preloadScene("Hall", (curcomplete, totalcount) => {
- this.progress.progress = (((curcomplete / totalcount) / 2) + 0.5)
- this.updatelaunchDesc()
- }, () => {
- this.StartGameNode.active = true
- })
- })
- }
- protected update(dt: number): void {
- if (this.progress.progress < 0.5) {
- this.progress.progress += 0.02
- this.updatelaunchDesc()
- }
- }
- updatelaunchDesc() {
- this.launchDesc.string = `${(this.progress.progress * 100).toFixed(0)}%`;
- }
- StartGame() {
- console.error('Hall');
-
- cc.director.loadScene("Hall")
- }
- LoadBundle(path: string): Promise<cc.AssetManager.Bundle> {
- return new Promise((resolve, reject) => {
- cc.assetManager.loadBundle(path, (err, bundle) => {
- if (err) {
- console.log('加载Bundle失败')
- reject(err)
- return;
- }
- resolve(bundle)
- });
- })
- }
- }
|