Page 1 of 1
How to import a body set from another b2dworld?
Posted: Sat Jun 22, 2013 6:49 am
by sijieshuai
I have two b2dworlds created by RUBE and I exported their corresponded json files. I loaded the b2dworld A's json file to create my world in my project, and now I want to import a character which has some bodies, fixtures and joints from b2dworld B to A. Is there some easy method to do this? Please give me some advices, thx

Re: How to import a body set from another b2dworld?
Posted: Sat Jun 22, 2013 7:36 am
by iforce2d
The most straightforward way is to modify the readFromFile function to load bodies into an existing world, instead of creating a new one. For this, you will need to pass the existing world to the function, like this:
readFromFile(const char* filename, string& errorMsg, b2World* world)
There are just a few lines of code you can change to make this happen. This thread here outlines the changes, although it may be a bit hard to follow:
viewtopic.php?f=6&t=125
If you need more explanation/help, just let me know.
Re: How to import a body set from another b2dworld?
Posted: Sun Jun 23, 2013 5:39 am
by sijieshuai
I followed your method, and now it works!!! Thank you!