Sample loader for Cocos2D-JS

General discussion about the R.U.B.E editor
Post Reply
strangelet
Posts: 1
Joined: Mon Aug 10, 2015 3:36 pm

Sample loader for Cocos2D-JS

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

Re: Sample loader for Cocos2D-JS

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