cb/assets/Script/ItemGuide.ts
2025-07-22 11:25:00 +08:00

89 lines
3.2 KiB
TypeScript

import JiaZai from "./JiaZai";
import MapConroler from "./Map";
const { ccclass, property } = cc._decorator;
@ccclass
export default class ItemGuide extends cc.Component {
static _instance: any;
time: number = 0;
//需要替换的三个道具节点
@property([cc.Node])
itemList: cc.Node[] = [];
@property(cc.Node)
itemGuide: cc.Node = null;
//道具节点的图片
@property([cc.SpriteFrame])
itemSpriteList: cc.SpriteFrame[] = [];
//飞的目标节点
@property([cc.Node])
targetNode: cc.Node[] = [];
onLoad() {
if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[0];
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[1];
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[2];
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[3];
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[4];
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[5];
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
this.itemList[0].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[6];
this.itemList[1].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[7];
this.itemList[2].getComponent(cc.Sprite).spriteFrame = this.itemSpriteList[8];
}
}
start() {
}
//关闭引导
closeGuide() {
this.node.children.forEach((item) => {
item.active = false;
})
this.node.children[0].active = true;
this.node.children[0].getComponent(cc.Sprite).spriteFrame = null;
this.itemGuide.active = true;
this.itemGuide.zIndex = 1000;
//获取目标节点的位置并且转换到itemGuide的位置的层级
let index = 0;
if (cc.fx.GameConfig.GM_INFO.level + 1 == 8) {
cc.fx.GameConfig.GM_INFO.hammerFirst = false;
index = 0;
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 11) {
cc.fx.GameConfig.GM_INFO.freezeFirst = false;
index = 1;
} else if (cc.fx.GameConfig.GM_INFO.level + 1 == 16) {
cc.fx.GameConfig.GM_INFO.magicAFirst = false;
index = 2;
}
let pos = this.targetNode[index].convertToWorldSpaceAR(cc.Vec3.ZERO);
pos = this.node.convertToNodeSpaceAR(pos);
this.itemGuide.zIndex = 1000;
//同时改变大小和位置
MapConroler._instance.setPropNum();
// if (this.itemGuide.active == true) {
cc.tween(this.itemGuide)
.to(0.9, { scale: 0.3, position: pos }) // 同时执行
.call(() => {
MapConroler._instance.setPropNum();
this.node.active = false;
})
.start();
// }
}
//显示引导
showGuide() {
this.node.active = true;
this.node.children[0].active = true;
}
// update (dt) {}
}