cc.Class({
    extends: cc.Component,

    properties: {
        aaa: cc.Node,
        bbbb: cc.Node,
    },

    onLoad() {

    },

    start() {
        this._armatureDisplay = this.aaa.getComponent(dragonBones.ArmatureDisplay);
        this._armature = this._armatureDisplay.armature();
        this.slot = this._armature.getSlot("武器_boundingBox");
        this.slot.updateTransformAndMatrix(); // 更新他的转化矩阵信息
        console.log(this.slot)
        console.log(this.slot.boundingBoxData)
        this.bbbb.removeFromParent();
        this.aaa.addChild(this.bbbb);

        let currentBone = this.slot.parent;
        let transform = currentBone.global;
        // !node.active && (node.active = true);
        this.bbbb.x = transform.x;
        this.bbbb.y = -transform.y;

        let rotation = 0;
        let scaleX = 1;
        let scaleY = 1;
        while (currentBone) {
            rotation += (currentBone.global.rotation * 180) / Math.PI;
            scaleX *= currentBone.global.scaleX;
            scaleY *= currentBone.global.scaleY;
            currentBone = currentBone.parent;
        }
        this.bbbb.rotation = rotation;
        this.bbbb.scaleX = scaleX;
        this.bbbb.scaleY = scaleY;

        let boxData = this.slot.boundingBoxData.vertices; //取到该处碰撞框的各个定点坐标
        let collider = this.bbbb.getComponent(cc.PolygonCollider);
        collider.points = [];

        for(let i = 0; i<boxData.length ; i++){
            let vec;
            if( i % 2 === 0){
                let result = {x:0,y:0};
                this.slot.globalTransformMatrix.transformPoint(boxData[i],boxData[i+1],result,false);  // 使用矩阵转化各个顶点坐标（一开始是正常的，随后慢慢偏移，怀疑是转化矩阵计算错误？）
                console.log(result.x,result.y)
                vec = cc.v2(result.x- this.bbbb.x ,this.bbbb.y+result.y);
                collider.points.push(vec);  // 根据顶点坐标绘制碰撞框
            }
        }
    },
    update(dt) {
        let currentBone = this.slot.parent;
        let transform = currentBone.global;
        // !node.active && (node.active = true);
        this.bbbb.x = transform.x;
        this.bbbb.y = -transform.y;
        let rotation = 0;
        let scaleX = 1;
        let scaleY = 1;
        while (currentBone) {
            rotation += (currentBone.global.rotation * 180) / Math.PI;
            scaleX *= currentBone.global.scaleX;
            scaleY *= currentBone.global.scaleY;
            currentBone = currentBone.parent;
        }
        this.bbbb.rotation = rotation;
        this.bbbb.scaleX = scaleX;
        this.bbbb.scaleY = scaleY;
    },
});
