Skip to main content
2 of 3
More descriptive title and tags. Removed thankyous.
Anko
  • 13.4k
  • 10
  • 55
  • 82

How do I turn an image into a Box2D physics object?

I'm using Box2D for a Game Programming course, and I was wondering if it is possible to choose the best shape and size of shape for the rigidbody/fixture that gets attached to a sprite based off of it's transparency. So far most of the project has been built around the idea of new content being easy to add (all data for enemies, terrain, etc. is stored in XML documents). Because of this, there will not be a new class for every enemy. This makes creating the fixture shapes difficult since it has to be a generic solution but still map realistically to the sprite when the game is being played. The best solution I've come up with so far is to somehow figure out where the majority of the non transparent pixels are in the sprite and build the shape from that.

Does something like this already exist? If not, would it be really hard to implement?

vdwtanner
  • 165
  • 1
  • 5