Gammerr Posted March 22, 2018 Share Posted March 22, 2018 So states are the right way of creating screens in the game, right? So let's say I have a menu state and I have a game state, so my game state looks like that: var gameState = { init: function(levelData) { this.levelData = levelData++; }, create: function() { var jumpLebel = game.add.text(140, 200, 'press ESC to jump to MENU', { font: '25px Arial', fill: '#ffffff'}); var escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC); escKey.onDown.addOnce(this.goToMenu, this); }, start: function() { this.game.state.start('menu', true, false, levelData); } }; Where is the right place to put my init variables of the game on the init function? after the init function? on the create function? should be in another state file? maybe the bootState? Can you help me with that structure please? Also I'm watching the tutorials of Pablo at udemy.com and he's not explaining why sometimes he's using 'this' and sometimes not, for example (section #4, Lecture #39 - Basic Structure): create: function() { this.ground = this.add.sprite(0, 500, 'ground'); var platform = this.add.sprite(0, 300, 'platform'); this.player = this.add.sprite(100, 200, 'player', 3); } Link to comment Share on other sites More sharing options...
samme Posted March 23, 2018 Share Posted March 23, 2018 init is fine. If an object is used inside several methods, it's convenient to save it on the state (e.g., this.ground). If it's used in one method only, it can be saved in a local variable. Link to comment Share on other sites More sharing options...
Recommended Posts