2

I have a game that uses Box2D. Sort of a platformer. It has multiple shapes, forming different objects of a stage. At this point I'm making those by creating separate body for each object (it is more convenient in my implementation of the engine), but it totally can be done with only one body having multiple fixtures attached to it.

Is there a reason for me to go extra mile and make my entire stages with only one body and multiple fixtures or the performance boost will be irrelevant?

P.S.(I'm making a mobile game. iOS and Android)

PanCotzky
  • 564
  • 2
  • 5
  • 12

1 Answers1

4

Making an entire stage with one body would be a horrible idea.

Consider:

  • you're losing out on all the methods of the Body API, such as the dynamic/static/kinematic differentiation,
  • from a programming perspective alone you are introducing a huge degree of coupling between your physical entities,
  • nowhere in the Box2D manual is there a mention of such an optimization. Indeed, the examples there are quite liberal with the creation of new bodies. I strongly suspect the engine does not expect it.

Even if you have actual, measured and identified problem with the number of bodies (and not the number of fixtures), I would advise against going in this direction.

Note that, in general, having multiple fixtures in one body is normal, and even necessary in a lot of cases. Just don't do it to your entire stage.

mikołak
  • 9,605
  • 1
  • 48
  • 70