Jump to content

Phaser States


Gammerr
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...