0
\$\begingroup\$

I have a Box2D world for each level in my game. When a level is completed, I want the player to be removed from the completed level's world and added to the next level's world. How do I do this?

\$\endgroup\$
1
\$\begingroup\$

I would start here ...

http://www.iforce2d.net/b2dtut/removing-bodies

Then end with a sprinkling of ...

http://www.iforce2d.net/b2dtut/bodies

I'm guessing the latter you already did, so essentially you are just doing the first part in reverse.

\$\endgroup\$
  • \$\begingroup\$ Does that mean that I have to destroy the body and re-create it in order to use it in a new World? It seems a tad inefficient that way to say the least. \$\endgroup\$ – manabreak Sep 18 '14 at 12:04
  • 1
    \$\begingroup\$ That's usually how physics engines work ... you can add things and remove things but its generally hard to get hold of a part of the world. That said ... this is C++ ... i live in a c# world so maybe you can somehow geta pointer and move that over to the new world somehow. I've never seen that though. \$\endgroup\$ – War Sep 18 '14 at 12:07
  • \$\begingroup\$ hmmm ... how about something like this ... gamedev.stackexchange.com/questions/27113/… \$\endgroup\$ – War Sep 18 '14 at 12:08
  • \$\begingroup\$ looks like in the solution he gets a ref to the body ... so you just need to pass that to your new world right? \$\endgroup\$ – War Sep 18 '14 at 12:08
  • \$\begingroup\$ The thing is, there's no way to pass a reference. There's no AddBody() function - just a CreateBody(). \$\endgroup\$ – manabreak Sep 18 '14 at 12:11

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.