cb/assets/Script/prop/Heng.ts
2026-04-29 18:09:45 +08:00

65 lines
2.0 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
import MapConroler from "../Map";
import NumberToImage from "../NumberToImage";
const { ccclass, property } = cc._decorator;
@ccclass
export default class Heng extends cc.Component {
static _instance: any;
time: number = 0;
_name: string = "";
type: string = "block"
// mapInfo: number[][] = [];
onLoad() {
}
start() {
}
init(name: string, time: number) {
this.time = time;
this._name = name;
this.node.getChildByName(name).active = true;
if (time) {
this.node.getChildByName(name).getChildByName("bg").active = true;
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName(this._name).getChildByName("bg").getChildByName("time"), false);
}
}
reduce() {
if (this.time > 0) {
if (this.type == "block") {
if (this.node.parent) {
if (this.node.parent.getComponent("Block").floor) {
return;
}
}
}
this.time -= 1;
NumberToImage.numberToImageNodes(this.time, 20, 8, "lock_", this.node.getChildByName(this._name).getChildByName("bg").getChildByName("time"), false);
// cc.fx.GameTool.numberScaleAction(this.node.getChildByName(this._name).getChildByName("bg").getChildByName("time"));
if (this.time <= 0) {
if (this.type == "block") {
if (this.node.parent) this.node.parent.getComponent("Block").type = 0;
}
this.node.destroy();
this.node.removeFromParent();
}
}
}
// update (dt) {}
}