Page 1 of 1

Sample loader for Cocos2D-JS

Posted: Tue Aug 11, 2015 2:02 pm
by strangelet
Hi,
I was using sample loader for Cocos2D-x V3 and b2dJson "merging files into one world" functionality.
Does someone from you have sample loader for Cocos2D-JS or loader for Javasript with possibility to merge more json files together into one world? (I am aware of loadrube.js)
Thanks.

Re: Sample loader for Cocos2D-JS

Posted: Tue Aug 11, 2015 5:13 pm
by iforce2d
In loadrube.js (I'll link for convenience: https://github.com/iforce2d/b2dJson/blo ... #L330-L332) you can see how a world is created and given as the target for loading into:

Code: Select all

var world = new b2World( gravity );
if ( ! loadSceneIntoWorld(worldJso, world) )
    return false;
Although I have not tried it, you should be able to just do that as many times as you need to, giving the same world each time as the target to load into. For example:

Code: Select all

var world = new b2World( gravity );
loadSceneIntoWorld(scene1, world);
loadSceneIntoWorld(scene2, world);
...
I do see one problem that might come up though... I think only the images of the last loaded scene would be available after this process. You could try changing line 319 like this to address that (again, untested):

Code: Select all

// before
world.images = loadedImages;
// after
world.images = world.images.concat( loadedImages );