IvesN Posted December 15, 2014 Share Posted December 15, 2014 Hi, i just recently started using phaser, (and programming in general ). im reading about phaser states and looking at examples i see this repeated in some of them var game = new Phaser.Game(width, height, Phaser.AUTO, 'test'); var BasicGame = function(game) {}; BasicGame.Boot = function (game) {}; BasicGame.Boot.prototype = etc etc . could someone explain me what are the advantages of using this pattern and not just use game.state.add. I have some understanding of prototype ineritance but can't figure this Link to comment Share on other sites More sharing options...
lewster32 Posted December 17, 2014 Share Posted December 17, 2014 It's for readability, extensibility (you could share functions between states and extend/modify them) and it keeps your code cleanly separated. Also, if you tried to add the state directly like so:game.state.add("SomeState", { create: function() { // blah blah }, update: function() { // blah blah blay }}You'll find scope rather tricky to work with from within the state; 'this' will not work as expected. You're best off keeping things more verbose otherwise maintainability of your code will quickly deteriorate. Link to comment Share on other sites More sharing options...
Recommended Posts