// 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 NewMode extends cc.Component { @property(cc.Label) label: cc.Label = null; @property text: string = 'hello'; btnStatic: number = 0; propName: string = ""; private imageLoadVersion: number = 0; onEnable() { const requestId = ++this.imageLoadVersion; const newMode = this.node.getChildByName("newmode"); if (!newMode) return; const config = cc.fx.GameConfig.NEW_LEVEL.find(item => item.level == cc.fx.GameConfig.GM_INFO.level + 1); this.propName = config ? config.name : ""; // 图片编号取配置名称的后缀,不能使用配置数组下标。 const match = /^daoju(\d+)$/.exec(this.propName); const index = match ? Number(match[1]) : -1; ["icon", "Introduction", "title"].forEach(name => { const node = newMode.getChildByName(name); const sprite = node && node.getComponent(cc.Sprite); if (!sprite) return; sprite.spriteFrame = null; if (index < 0 || index > 33) return; const path = `Window_Prop/${name}${index}`; cc.resources.load(path, cc.SpriteFrame, (err, spriteFrame: cc.SpriteFrame) => { if (!cc.isValid(this, true) || !cc.isValid(sprite, true) || requestId !== this.imageLoadVersion) return; if (err) { cc.error("NewMode 图片加载失败:", path, err); return; } sprite.spriteFrame = spriteFrame; }); }); } onDisable() { this.imageLoadVersion++; } 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 == 0) { this.node.active = false; this.node.emit("new-mode-confirmed"); } else if (this.btnStatic == 1) { cc.fx.GameTool.getUserAvatar(() => { }) cc.director.loadScene("HomeScene"); } else if (this.btnStatic == 2) { cc.fx.GameConfig.enterGameSceneWhenReady(); } else if (this.btnStatic == 3) { this.node.active = false; this.node.emit("new-mode-closed"); } } // update (dt) {} }