shefyg wrote:
Maybe all the copies are done after the body is created.
The copies are done during CreateFixture(). It winds up calling b2Fixture.Create()...
Code:
b2internal function Create( body:b2Body, xf:b2Transform, def:b2FixtureDef):void
{
// a few things snipped to save space...
// here it copies things out of the Fixture def
m_userData = def.userData;
m_friction = def.friction;
m_restitution = def.restitution;
m_filter = def.filter.Copy();
// and here it makes a copy of the shape
m_shape = def.shape.Copy();
}
OTOH, there's actually a warning in the documentation that says, "you cannot reuse shapes". Whereas, the fixtureDefs are documented as "You can reuse fixture definitions safely."
It's possible that this is an old warning that no longer applies, because with the Box2D code clearly making a copy of the shape, I don't see how changing the shape later would be a problem. I know I made multi-shape bodies in my own program while redefining the shape object.
That said, the fact that you had troubles makes me think the warning is still valid, and I may have just gotten away with it for some reason.
shefyg wrote:
If you look at the example I got, he does the same thing - 2 different fixtures.
If you have more simplified example of code that work, I would be happy to see it (and it sure will help others who check this post)
Fixtures are definitely reusable though. Even the documentation says you can do it.
The code I posted in the previous message is untested, but it should just drop in to your project, and perhaps verify whether or not the shapes can be reused. It replaces the section of your latest post, starting from the "//4. set body shape" comment, up to but not including the last two lines in your version.