// 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";

const { ccclass, property } = cc._decorator;



@ccclass
export default class Adhesive extends cc.Component {
    static _instance: any;
    time: number = 60;
    pos: any = { x: 0, y: 0 };
    target: any;

    onLoad() {
        this.pos.x = this.pos.y = 0;
        this.target = null;
    }

    start() {
    }

    init(node) {
        this.pos.x = node.x - this.node.x;
        this.pos.y = node.y - this.node.y;
        this.target = node;
    }

    remove() {
        this.target = null;
        for (let j = 0; j < this.node.children.length; j++) {
            if (this.node.children[j].active == true) {
                this.node.children[j].getComponent(sp.Skeleton).setAnimation(0, "animation", false);
            }
        }
        setTimeout(() => {
            this.node.active = false;
        }, 2000);
    }


    update(dt) {
        if (this.target != null) {
            this.node.x = this.target.x - this.pos.x;
            this.node.y = this.target.y - this.pos.y;
        }
    }
}
