cb/assets/Script/NewMode.ts
2025-08-05 17:59:54 +08:00

67 lines
1.9 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("newmode").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) {}
}