colorBlock/assets/Script/NewMode.ts
YZ\249929363 4ca3daaa48 提交
2025-06-26 14:44:43 +08:00

67 lines
1.8 KiB
TypeScript

// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const {ccclass, property} = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
btnStatic: number = 0;
propName: string = "";
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start () {
for(let i=0; i<cc.fx.GameConfig.NEW_LEVEL.length; i++){
if((cc.fx.GameConfig.GM_INFO.level+1) == cc.fx.GameConfig.NEW_LEVEL[i].level){
this.propName = cc.fx.GameConfig.NEW_LEVEL[i].name;
const path = 'Window_Prop/' + this.propName;
cc.resources.load(path, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => {
if (err) {
console.error('动态加载背景图失败:', err);
return;
}
this.node.getChildByName("icon").getComponent(cc.Sprite).spriteFrame = spriteFrame;
})
break;
}
}
}
setMode(mode:number){
this.btnStatic = mode;
let name = "GameScene";
if(mode == 1){
name = "HomeScene";
}
cc.director.preloadScene(name, ()=>{
})
}
clickBtn(){
cc.fx.AudioManager._instance.playEffect("anniu_Big",null);
if(this.btnStatic == 1){
cc.director.loadScene("HomeScene");
}
else if(this.btnStatic == 2){
cc.director.loadScene("GameScene");
}
}
// update (dt) {}
}