Jump to content

Good practice - file structure


Recommended Posts

Hi guys!  :)

So this is probably an easy question to answer, but everything I tried so far broke my code. So I am using states



MMM.MainGame = function(game){

MMM.MainGame.prototype = {

    create: function() { ....





The issue that I am having is that I will not have that many states, besides booting, preloading, and the actual game, so my main game file is already getting pretty big with 100 lines alone for zooming in and out.

Is there a way to export these functions somehow to external js files and put them together in the MainGame.prototype

Something like extends?


I need some good practice advice here, because my main file will otherwise easily become thousands of lines and just one messy hell.

Link to comment
Share on other sites

I fixed my problem by using ES6, worked like a charm and wasn't too difficult to implement into my already existing state seperation.


For those of you who encountered the same problem. I am exporting my functions in seperate files and then import them in my main file.

Link to comment
Share on other sites

Glad you figured it out, basically you don't need ES6 to do that, simply create new files and add them as separate scripts, also you don't "have" to include everything in your MainGame, if you need something that exists on the MainGame you can store that in a global object like this:

var registry = { mainGameVelocity:0};MMM.MainGame.create = function(){ this.velocity = 20; registry.mainGameVelocity = this.velocity;};

Also mark your answer as correct, so that others can find it more easily.



Link to comment
Share on other sites


  • Recently Browsing   0 members

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