1
\$\begingroup\$

I am making a game with a sort of "playfield" where the game takes place, acting as boundaries on a top-down shooter. I am using Box2D for physics, and I am questioning which of the following would be the most efficient. One option would be to have the playfield represented by a single static body, with four fixtures attached to it (top, bottom, left, and right walls). The other option would be to have four static bodies, one for each border fixture. Which is the fastest for Box2D to process?

\$\endgroup\$
0
\$\begingroup\$

I know this is probably late but an answer can be found here: https://stackoverflow.com/a/21172599.

"It is faster to attach several shapes to a static body than to create several static bodies with a single shape on each one. Internally, Box2D sets the mass and inverse mass of static bodies to zero. This makes the math work out so that most algorithms don't need to treat static bodies as a special case."

\$\endgroup\$
  • \$\begingroup\$ This answers my question perfectly. What I was using was working, so I left it and didn't change it. But now that I know that it's faster, I'll continue to use it. Thanks! \$\endgroup\$ – pjrader1 Aug 18 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.