Page 1 of 1

loading two json

Posted: Sat Jul 13, 2013 8:45 am
by anupgupta@inbox.com
hello

i have created my level in rube which contains a bike and platform.

now i would like to keep the bike seperate in biks.json file and my level in level01.json separate.

now can i load both bike.json and level01.json at once together.

i tried but it was showing the last .json file loaded in the simulator.

Re: loading two json

Posted: Sun Jul 14, 2013 1:29 am
by iforce2d
I will assume you are using C++ and using the b2dJson source code from github

The function b2dJson::readFromFile takes an optional parameter for a world to load the bodies into. If no parameter is given it will create a world to use, otherwise it will use an existing world that you pass to it:

Code: Select all

string errorMsg;

b2dJson json1;
b2World* world = json1.readFromFile( "level1.json", errorMsg );

b2dJson json2;
json2.readFromFile( world, "bike.json", errorMsg, world ); 
When finding items in the scene, remember to use the correct json object to locate them, eg.:

Code: Select all

b2Fixture* finishLine = json1.getFixtureByName( "finish" ); // use json1
b2Fixture* bikeFrame = json2.getFixtureByName( "frame" ); // use json2