Jump to content

How to split my code ?


Faktori
 Share

Recommended Posts

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

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

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/src

also DrHayes blaster.. https://github.com/drhayes/blaster/tree/master/src

Link to comment
Share on other sites

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/src

also DrHayes blaster.. https://github.com/drhayes/blaster/tree/master/src

:wub:

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...