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.

Share this post

Link to post
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.

Share this post

Link to post
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.



Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.