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?
1 Answer
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.
-
\$\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\$ Sep 18, 2014 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\$– WarSep 18, 2014 at 12:07
-
\$\begingroup\$ hmmm ... how about something like this ... gamedev.stackexchange.com/questions/27113/… \$\endgroup\$– WarSep 18, 2014 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\$– WarSep 18, 2014 at 12:08
-
\$\begingroup\$ The thing is, there's no way to pass a reference. There's no
AddBody()
function - just aCreateBody()
. \$\endgroup\$ Sep 18, 2014 at 12:11