negue Posted March 12, 2014 Share Posted March 12, 2014 Hey, i'm wondering if this feature maybe needed in Phaser. We all can use States, which is very nice and easy to separate files / logic, but we can't "easy" pass parameters from the MainMenu to the "Game"-States. With easy I mean something like this:game.state.startWithParams('name', { myParam1: true });// inside the State on the constructorfunction myState(game, params){// {...}}Ofcouse I could just attach my parameters to my gameObject. How do you handle your parameters to your "main game state". Link to comment Share on other sites More sharing options...
ctmartinez1992 Posted March 13, 2014 Share Posted March 13, 2014 I agree, to my knowledge there is no standard way to pass variables between state transitions, which i think it would be very handy, you can however use global/static variables Link to comment Share on other sites More sharing options...
Nick Posted August 11, 2014 Share Posted August 11, 2014 You can pass additional parameters via game.state.start();e.g.game.state.start('Leaderboard', true, false, customParam1, customParam2);The first two params tell Phaser whether or not to clear the game world and cache. Any params after those are custom and will be sent to your state's 'init' function if it exists. Then within your state you need to create the init function: var LeaderboardState = function() { }; LeaderboardState.prototype = { init: function(customParam1, customParam2) { }}; codevinsky, phaserdragoon, mikkoh85 and 9 others 10 2 Link to comment Share on other sites More sharing options...
BdR Posted December 11, 2014 Share Posted December 11, 2014 I read here that you can reference variables through the StateManager, something like this.game.state.states['statename'].variable, see code below // Phaser.state for level select screen mygame.LevelSelect = function(game){ this.game = game; // keep reference to main game object this._selectedLevel = 0; }; mygame.LevelSelect.prototype = { create: function(){ //etc. onLevelSelected: function() { // pass variables to 'MainGame' state this.game.state.states['MainGame']._currentLevel = this._selectedLevel; this.game.state.states['MainGame']._showTutorial = (this._selectedLevel == 1); // only show tutorial on level 1 }, //etc. }; // Phaser.state for main game loop mygame.MainGame = function(game){ this.game = game; // keep reference to main game object this._showTutorial = false; this._currentLevel = 0; }; mygame.MainGame.prototype = { create: function(){ //etc. Wunderforce 1 Link to comment Share on other sites More sharing options...
Recommended Posts