第一个可以运行的TypeScripts

import { _decorator, Component, director, Input, Node, NodeEventType, ProgressBar } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('loading')
export class loading extends Component {

@property(ProgressBar)
progressBar: ProgressBar = null;

@property(String)
nextScene: string = "menu";

protected onLoad(): void {
    if(this.progressBar){
        this.progressBar.node.active = false;
    }
    this.node.on(Input.EventType.MOUSE_UP,this.onButonClick, this);
}
    onButonClick(){
        if(this.progressBar){
            this.progressBar.node.active = true;
            this.progressBar.progress = 0;
            this.schedule(this.updateProgressBar, 0.1);
        }
    }
    updateProgressBar() {
        if (this.progressBar.progress < 1) {
            this.progressBar.progress += 0.1;
        } else {
            this.unschedule(this.updateProgressBar);
            director.loadScene(this.nextScene);
            // Add logic to switch to the next scene if needed
        }
    }
protected onDestroy(): void {
    this.unschedule(this.updateProgressBar);
}
    update(deltaTime: number) {
        
    }
}

 

posted @ 2025-01-02 16:49  多见多闻  阅读(23)  评论(0)    收藏  举报