Rasmus Posted October 12, 2014 Share Posted October 12, 2014 Is there an example on how to organize bigger projects in multiple files and classes? Quote Link to comment Share on other sites More sharing options...
joshcamas Posted October 12, 2014 Share Posted October 12, 2014 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:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript This stuff is quite confusing for a while in javascript. :/ Quote Link to comment Share on other sites More sharing options...
OttoRobba Posted October 12, 2014 Share Posted October 12, 2014 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 Quote Link to comment Share on other sites More sharing options...
joshcamas Posted October 12, 2014 Share Posted October 12, 2014 Even though OttoRatta wrote his answer for phaser, everything is still basically the same for any project in javascript, and for games specifically. Good answer Otto. Quote Link to comment Share on other sites More sharing options...
lukaszwojciak Posted October 13, 2014 Share Posted October 13, 2014 I like this https://github.com/wojciak/dustPlaygroundApp Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted October 13, 2014 Share Posted October 13, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.