loading two json

General discussion about the R.U.B.E editor
Post Reply
anupgupta@inbox.com
Posts: 6
Joined: Wed Jul 10, 2013 6:02 pm

loading two json

Post 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.
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: loading two json

Post 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
Post Reply