Squize Posted September 16, 2013 Share Posted September 16, 2013 This may be a naive question, apologies if so, I'm just wondering how everyone structures the actual files of their Phaser games. By that I mean, do you break each core section out into it's own .js file. For example, I'm thinking I'll have a file ( I so want to call it a class ) just for the preload method, where I can hide away all the game.load calls, as I don't want to be seeing them in my main.js file every day. My current thinking is I'll have a Main file that would have my global vars and kickstart the game off, ie game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); And then my preload method ( Argh, function ) would be in it's own preloader.js and so on. Is this a valid / common approach, or am I just clinging too much to OOP where it doesn't fit ? Cheers, Squize. Link to comment Share on other sites More sharing options...
Hsaka Posted September 16, 2013 Share Posted September 16, 2013 That's exactly the approach that I use, except that I tend to split things like preloading etc. into states primarily; each in its own js file. So my preloader (Preloader.js) is a state inside of which I handle all of the preloading tasks and what not and then transition into the next state (maybe the title screen). You can see an example of this in phaser/wip/examples/state plicatibu and Squize 2 Link to comment Share on other sites More sharing options...
Squize Posted September 16, 2013 Author Share Posted September 16, 2013 Excellent, thanks for the ( Frighteningly ) quick reply mate Squize. Link to comment Share on other sites More sharing options...
rich Posted September 16, 2013 Share Posted September 16, 2013 I do the same but it depends on the size of the game how far I'll break it down. For Wolfblood I had a sub-folder for every mini-game as there were loads of them. Then inside those I had a Preloader, the main Game and often some support files too (game specific objects). In the root I had a Boot file, the Preloader and some BBC specific stuff. I would recommend the use of a Boot state, I made a post on this forum about it a week or two ago, it's worth reading imho as it shows you how to make a proper preloader Link to comment Share on other sites More sharing options...
Squize Posted September 16, 2013 Author Share Posted September 16, 2013 Cool thanks mate. I'm Class happy so I'm trying to calm that down a little bit as its taken on OCD levels ( I did a quick file count for the source files in O2 the other day, 434, which is mental ).I think I may have used your Boot method without realising it, just a simple main file with the update method in it and using a function pointer to handle my state machine ( I'll check yours out though, I'm devouring any and all examples atm ).In all honesty I actually enjoyed coding in js today for the first time ever, I'm panting for the Phaser docs ( I guess I'm the first to mention that ) but having some AS3 like structure was really nice. Also using Light Table is like coding in the future.Squize. Link to comment Share on other sites More sharing options...
Recommended Posts