Okay. I have a series of movieclips, each one containing a collideObj instance which references a b2BodyDef. I use them to arrange a scene in the IDE and then loop through them and add them to the world, and replace the collideObj definitions with the resulting b2Bodys. This works great, but now I'm trying to add joints. Each joint movieclip is a line with an invisible mc at each end. This is how I translate them into b2DistanceJointDefs:
The joints are added to the scene in a different class:
If I connect a static with a dynamic body, the dynamic one goes crazy, flickering all over the place apparently at random. If I connect two dynamic bodies together, they flicker around a bit and disappear. Is there anything wrong with what I've done to set the b2DistanceJointDefs? If I set the anchorPoints to 0,0 the same effect occurs. I should say that I'm still using 1.4.3, because I don't want to jump horses midstream (at least not quite yet).
Code:
public function initJoints(){
for(var i=0;i<numChildren;i++){
trace(i)
child = getChildAt(i)
if (child.collideObj is b2DistanceJointDef){
// trace("Found joint",child);
var joint = child.collideObj
var end1 = child.getChildByName("end1") //These sit at the ends of the line segment
var end2 = child.getChildByName("end2")
var pt1 = new Point(end1.x,end1.y);
var pt2 = new Point(end2.x,end2.y);
trace(end2.x,end2.y)
pt1 = child.localToGlobal(pt1); //Where are we actually?
pt2 = child.localToGlobal(pt2);
for(var j in platforms){ //Loop through all movieclips that hold b2Body refs
trace("finding collided...");
trace(platforms[j]);
if(platforms[j].hitTestPoint(pt1.x,pt1.y)){ //If the left endpoint is hitting this body
trace(platforms[j])
joint.body1 = platforms[j].collideObj;
pt1 = platforms[j].globalToLocal(pt1);//Find where it is hitting relative to the body
trace(pt1.x,pt1.y);
joint.anchorPoint1 = new b2Vec2(pt1.x*.1,pt1.y*.1);
} else if (platforms[j].hitTestPoint(pt2.x,pt2.y)){
joint.body2 = platforms[j].collideObj;
pt2 = platforms[j].globalToLocal(pt2)
joint.anchorPoint2 = new b2Vec2(pt2.x*.1,pt2.y*.1); //*.1 is the scale factor
}
}
child.collideObj = joint;
joints.push(joint);
}
}
// trace(joints.length);
}
for(var i=0;i<numChildren;i++){
trace(i)
child = getChildAt(i)
if (child.collideObj is b2DistanceJointDef){
// trace("Found joint",child);
var joint = child.collideObj
var end1 = child.getChildByName("end1") //These sit at the ends of the line segment
var end2 = child.getChildByName("end2")
var pt1 = new Point(end1.x,end1.y);
var pt2 = new Point(end2.x,end2.y);
trace(end2.x,end2.y)
pt1 = child.localToGlobal(pt1); //Where are we actually?
pt2 = child.localToGlobal(pt2);
for(var j in platforms){ //Loop through all movieclips that hold b2Body refs
trace("finding collided...");
trace(platforms[j]);
if(platforms[j].hitTestPoint(pt1.x,pt1.y)){ //If the left endpoint is hitting this body
trace(platforms[j])
joint.body1 = platforms[j].collideObj;
pt1 = platforms[j].globalToLocal(pt1);//Find where it is hitting relative to the body
trace(pt1.x,pt1.y);
joint.anchorPoint1 = new b2Vec2(pt1.x*.1,pt1.y*.1);
} else if (platforms[j].hitTestPoint(pt2.x,pt2.y)){
joint.body2 = platforms[j].collideObj;
pt2 = platforms[j].globalToLocal(pt2)
joint.anchorPoint2 = new b2Vec2(pt2.x*.1,pt2.y*.1); //*.1 is the scale factor
}
}
child.collideObj = joint;
joints.push(joint);
}
}
// trace(joints.length);
}
The joints are added to the scene in a different class:
Code:
var joints = collision.joints
for(var i in joints){
m_world.CreateJoint(joints[i]);
}
for(var i in joints){
m_world.CreateJoint(joints[i]);
}
If I connect a static with a dynamic body, the dynamic one goes crazy, flickering all over the place apparently at random. If I connect two dynamic bodies together, they flicker around a bit and disappear. Is there anything wrong with what I've done to set the b2DistanceJointDefs? If I set the anchorPoints to 0,0 the same effect occurs. I should say that I'm still using 1.4.3, because I don't want to jump horses midstream (at least not quite yet).