Jump to content

Organizing bigger projects?


Recommended Posts

This seems like more of a javascript question.


Multiple files is easy - just put them in multiple files, and "import" them in the HTML file just like any other javascript file.

For classes, (Objects in javascript), go here:



This stuff is quite confusing for a while in javascript. :/

Link to comment
Share on other sites

EDIT: Aw, sorry, I thought it was a Phaser question. I'm not 100% sure of how BabylonJS works but it *should* be similar since it is a Javascript matter, mostly.


Hey Rasmus, I'll try to be brief :)


Working with multiple files is easy - like josh pointed out, you just source them in your html, like this:



Working with multiple states is pretty easy in Phaser - not so sure about BabylonJS, sorry :(



As far as classes go, I do pretty much what ToastedWare taught in a tutorial. Here is how my folders look:



The way the entities work is simple, below is an example:

Background = function(game) {    this.game = game;};Background.prototype = {    create: function() {        this.background = game.add.tileSprite(0, 0, game.world.width, 1363, 'background');    },    update: function() {        this.background.tilePosition.y += player.sprite.speed / 5;    },};

Then on the play.js file, I do this:

var playState = {	create: function() {		background = new Background(game);		background.create();	},	update: function() {		background.update();        },};

So far this has worked really well and has helped me get organized. No more getting lost looking for functions inside a file!


I hope this helps :)

Link to comment
Share on other sites

The order of listing script files can be important.  Once you know what the correct order is you might want to make a little .bat or .sh to codify / document it.  If you want to put it in multiple html files, having one consolidated .js may someday save you a lot of pain when things do not work on all your .html's.


in a build.sh:

cat first.js second.js >combined.js


in a build.bat I think you use copy instead of cat & the last arg is the output file, so no need to redirect.

Link to comment
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.
  • Create New...