Attached is a project that demonstrates my solution to attaching MovieClips to Box2D bodies. The advantage of this approach is that you can literally drag 'n' drop bodies from your library into a Box2d world. Once they're on the stage, you can scale & rotate them, as well as set "density" and "isSleeping" via the properties inspector. Here's how it works:
There's 2 main classes - Body and World - that extend MovieClip and correspond to b2Body and b2World classes. Within the attached .fla project, there's an instance of the World symbol on the stage. Within the World symbol are instances of symbols that inherit from Body. When the project is run, the World instance initializes all the bodies and starts the Box2D simulation. For each iteration, the Body-extending MovieClips are updated with data from the Box2d simulation.
So, to "box2d-enable" a symbol, you have to make it extend "Body", then override the "createShapes" function to tell Box2d how your symbol is shaped. There's three examples in the demo - SampleBox, SamplePolygon and SampleCircle.
My goal originally was to parse the MovieClip shape data to create Box2d shapes automatically, but this turned out to be impossible. It doesn't look like you can get raw shape data from a MovieClip during runtime in ActionScript (please correct me if I'm wrong).
I don't know how well this will perform on systems other than my own. Haven't really played around with the FrameRate or b2Settings. I'm justing posting this to help anyone that may be trying to achieve the same effect.
There's 2 main classes - Body and World - that extend MovieClip and correspond to b2Body and b2World classes. Within the attached .fla project, there's an instance of the World symbol on the stage. Within the World symbol are instances of symbols that inherit from Body. When the project is run, the World instance initializes all the bodies and starts the Box2D simulation. For each iteration, the Body-extending MovieClips are updated with data from the Box2d simulation.
So, to "box2d-enable" a symbol, you have to make it extend "Body", then override the "createShapes" function to tell Box2d how your symbol is shaped. There's three examples in the demo - SampleBox, SamplePolygon and SampleCircle.
My goal originally was to parse the MovieClip shape data to create Box2d shapes automatically, but this turned out to be impossible. It doesn't look like you can get raw shape data from a MovieClip during runtime in ActionScript (please correct me if I'm wrong).
I don't know how well this will perform on systems other than my own. Haven't really played around with the FrameRate or b2Settings. I'm justing posting this to help anyone that may be trying to achieve the same effect.