hyude Posted October 9, 2014 Report Share Posted October 9, 2014 Hello. I am trying to learn how game state/switch state workds in phaser.I use a boilerplate from https://github.com/EnclaveGames/Cyber-Orb. I tested it in browser and it works. When I read the source code, something intrigues me.All of Game State only declared as function(game) with given preload() and create() method.The Phaser Docs also said you can add a simple function object as game state (it doesn't have to be a Phaser.State object). I then tried to call console.debug(this) during state preload(), and the displayed object is a completed state object with add, load, etc. My question : Does Phaser somehow assign all of it during initiialization?How can the simple function object now have all object available for it? I tried searching in StateManager class and Game class source code and found none of it. Where does exactly Phaser did that, and how did it achieve that?Thanks Quote Link to comment Share on other sites More sharing options...
bulkan Posted October 9, 2014 Report Share Posted October 9, 2014 All of Game State only declared as function(game) with given preload() and create() method.The Phaser Docs also said you can add a simple function object as game state (it doesn't have to be a Phaser.State object). I then tried to call console.debug(this) during state preload(), and the displayed object is a completed state object with add, load, etc. My question : Does Phaser somehow assign all of it during initiialization?How can the simple function object now have all object available for it? When you pass a simple object with those methods to Phaser it callsthis.state = new Phaser.StateManager(this, state);https://github.com/photonstorm/phaser/blob/26fe06e00c7c85bbe76ee8827a0cbf48dbf5f93d/src/core/Game.js#L313 Phaser internally creates a new StateManager from the `state` that is passed into the `Game` constructor.Phaser.StateManager can accept either a State or Object Quote Link to comment Share on other sites More sharing options...
hyude Posted October 9, 2014 Author Report Share Posted October 9, 2014 Edit : Wait, but doesnt that code means Phaser initialize game.state object to referenced at State Manager with given pendingState? My question is why the basic function object which get added by game.state.add(obj) somehow get all their properties?Where does this happen? 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.