// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        target: {
            default: null,
            type: cc.Node,
            serializable: true,
        },

    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {
        // cc.log('Icon位置：', this.target.position, this.node.parent.convertToNodeSpaceAR(this.target.position), this.target.convertToWorldSpaceAR(this.target.position))
        // cc.log('Node位置：', this.node.position, this.target.parent.convertToNodeSpaceAR(this.node.position), this.target.convertToWorldSpaceAR(this.node.position))

     
        setTimeout(() => {
            let targetWorldPos = this.target.parent.convertToWorldSpaceAR(this.target.getPosition());
            let moveToSpacePos =  this.node.parent.convertToNodeSpaceAR(targetWorldPos);
            cc.log('Node移动的位置：', moveToSpacePos);
            // 创建一个移动动作
            var action = cc.moveTo(2,moveToSpacePos);
            // 执行动作
            this.node.runAction(action);
        }, 1000);

    },

    update(dt) {


    },
});
