RopeJoint代码动态创建 无法设置otherbody等属性

var img:Sprite = new Sprite();                  
//加载显示图片,坐标位于100,50
img.loadImage("res/layabox.png");
img.x=(Laya.stage.width-256)/2;
//添加到舞台
Laya.stage.addChild(img);

var img2:Sprite = new Sprite();
//加载显示图片,坐标位于100,50
img2.loadImage("res/layabox.png");
img2.x=(Laya.stage.width-256)/2+100;
img2.y=(Laya.stage.height-256)/2-50;
//添加到舞台
Laya.stage.addChild(img2);

sp=img2;
img2.addComponent(BoxCollider);
(img2.getComponent(BoxCollider) as BoxCollider).width=256;
(img2.getComponent(BoxCollider) as BoxCollider).height=256;
img2.addComponent(RigidBody);

img.addComponent(BoxCollider);
(img.getComponent(BoxCollider) as BoxCollider).width=256;
(img.getComponent(BoxCollider) as BoxCollider).height=256;
img.addComponent(RigidBody);
(img.getComponent(RigidBody) as RigidBody).type="kinematic";
img2.addComponent(RopeJoint);
(img2.getComponent(RopeJoint) as RopeJoint).otherBody=img.getComponent(RigidBody) as RigidBody;
(img2.getComponent(RopeJoint) as RopeJoint).otherAnchor=new Array()[128,128];
(img2.getComponent(RopeJoint) as RopeJoint).selfAnchor=new Array()[128,128];
(img2.getComponent(RopeJoint) as RopeJoint).maxLength=500;


(img2.getComponent(RopeJoint) as RopeJoint).collideConnected=false;
已邀请:

神马小刀

赞同来自:

看了下源码 搞明白了 首次设置有效是说的在awake里面调用createjoint 所以需要先设置好 然后再addchild 就可以了

该问题目前已经被锁定, 无法添加新回复

商务合作
商务合作