How to import a body set from another b2dworld?
- 
				sijieshuai
 - Posts: 13
 - Joined: Tue May 14, 2013 1:51 pm
 
How to import a body set from another b2dworld?
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?
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.
			
			
									
						
										
						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.
- 
				sijieshuai
 - Posts: 13
 - Joined: Tue May 14, 2013 1:51 pm
 
Re: How to import a body set from another b2dworld?
I followed your method, and now it works!!! Thank you!