Hey everyone,
I am trying to build a new b2body based on other b2bodies.
So the basic set up is that I have an object, and that object is made up of other objects. So to make the object, I need to add all the other object's shapeDefs.
What I would like to do is iterate through the shapeDefs that make up the bodies that I am trying to add to my new body (thus forming a compound shape).
So something like this:
body = Common.getWorld().CreateBody(bodyDef); // the compound body
body.addOtherBody(body2); // 2 bodies that I would like to add to this body
body.addOtherBody(body3);
.
.
private function addOtherBody(otherBody:b2Body):void {
// go through all the shapes in the body and add them to the new compound body
while (otherBody.getShapeList() != null) {
body.CreateShape(otherBody.getShapeList());
// go to next shape in body
}
}
The problem I am having is that CreateShape() takes a b2ShapeDef, and not a b2Shape. Is there anyway to get the shapeDef of a Shape?
Or a better way to do what I am looking to do?
Many thanks!
Alex
I am trying to build a new b2body based on other b2bodies.
So the basic set up is that I have an object, and that object is made up of other objects. So to make the object, I need to add all the other object's shapeDefs.
What I would like to do is iterate through the shapeDefs that make up the bodies that I am trying to add to my new body (thus forming a compound shape).
So something like this:
body = Common.getWorld().CreateBody(bodyDef); // the compound body
body.addOtherBody(body2); // 2 bodies that I would like to add to this body
body.addOtherBody(body3);
.
.
private function addOtherBody(otherBody:b2Body):void {
// go through all the shapes in the body and add them to the new compound body
while (otherBody.getShapeList() != null) {
body.CreateShape(otherBody.getShapeList());
// go to next shape in body
}
}
The problem I am having is that CreateShape() takes a b2ShapeDef, and not a b2Shape. Is there anyway to get the shapeDef of a Shape?
Or a better way to do what I am looking to do?
Many thanks!
Alex