BrokenSkyDev Posted February 22, 2015 Share Posted February 22, 2015 Hi Everyone, This question is going to be quite broad, but what is best way to have multiple levels in your game. I have seen posts about copying and pasting states and changing the content and changing it, but that seems rather inefficient. Thanks. Link to comment Share on other sites More sharing options...
mwatt Posted February 25, 2015 Share Posted February 25, 2015 I have had some success with this approach: I create a JSON file that holds level definitions - number and type of sprite-based objects, placement and basic behaviors for each kind of game object that can change in a level. The format is a big array of objects, with each object representing a level and itself having multiple arrays specifying the kind of stuff I already mentioned. In Game create I lay down stuff that doesn't change. Upon each level change I show level change animation and then I load up the new level based upon the level definition for that level. I try to create object pools for stuff that gets re-used a lot instead of creating and destroying stuff for each level, to avoid gc jitter, but I end up doing some destroying and recreating some stuff for sure. I know under the hood that Pixi does a lot of texture caching, but most of the objects I am caching tend to be "class-based" built upon a basic sprite, but having additional behaviors and properties. Once you have put in the work to do this, you can create new levels with a text editor. Granted, certain kinds of games lend themselves more to this approach than others. Link to comment Share on other sites More sharing options...
Arcanorum Posted February 25, 2015 Share Posted February 25, 2015 How are states inefficient? This is the kind of thing they are meant to be used for. Link to comment Share on other sites More sharing options...
Recommended Posts