Faktori Posted November 20, 2015 Share Posted November 20, 2015 Hi everyone, working on my first project at the moment, and got over 1500 lines of code in my main.js file by now.How should i split it ? I have the first part setting up object prototypes for any element of the game, with it's own update and stuff, then I have my mainState.Should I cut each object in a single file, then have a file for each state and link it all in the same HTML ? I'm really not sure what is the way to go with this.Do you guys have any tips on this ? Thanks !! Link to comment Share on other sites More sharing options...
BrunoHautenfaust Posted November 20, 2015 Share Posted November 20, 2015 Should I cut each object in a single file, then have a file for each state and link it all in the same HTML ? I'm really not sure what is the way to go with this. Yes. Break your code into little (and reusable) pieces. Cramming everything in one big file is not good.Only one thing to keep in mind - when you link them in the HTML file, pay attention to the order in which you're placing them. Link to comment Share on other sites More sharing options...
jmp909 Posted November 20, 2015 Share Posted November 20, 2015 are you comfortable with things like ES6, browserify, node, grunt, require etc? have a look at the phaser source, it's a good example of how to split out responsibilites and using one function per task etc https://github.com/photonstorm/phaser/tree/master/srcalso DrHayes blaster.. https://github.com/drhayes/blaster/tree/master/src webcaetano and drhayes 2 Link to comment Share on other sites More sharing options...
webcaetano Posted November 21, 2015 Share Posted November 21, 2015 are you comfortable with things like ES6, browserify, node, grunt, require etc? have a look at the phaser source, it's a good example of how to split out responsibilites and using one function per task etc https://github.com/photonstorm/phaser/tree/master/srcalso DrHayes blaster.. https://github.com/drhayes/blaster/tree/master/src Link to comment Share on other sites More sharing options...
Faktori Posted November 21, 2015 Author Share Posted November 21, 2015 Thanks guys for your advices, I'll check those projects out to see how it's done. Not really comfortable using packages to do things for me when I don't understand what it's doing, pretty new to all this so far Edit : so yeah I just put my player object prototype into a new js file and linked it before my main and it works. Great ! Link to comment Share on other sites More sharing options...
Recommended Posts