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?
1 Answer
\$\begingroup\$
\$\endgroup\$
1
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."
-
\$\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\$– pjrader1Commented Aug 18, 2016 at 17:58