Search the Community
Showing results for tags 'menu states'.
-
I'm currently having troubles with states in my game. I just started using it so I'm certain I'm making a dumb mistake, but if you could help I would really appreciate it. The problem I'm having is that when I hit the Space Button, it triggers the start function in stateMENU again and again. Shouldn't the stateMENU end and not respond/react anymore? If you need any more information, let me know. Here's My Code This is in LOAD.js: var stateLOAD = { preload: function(){ this.game.stage.backgroundColor = "#FF0921"; this.game.load.spritesheet('player','redThief.png',50,95); }, create: function(){ this.game.state.start('menu'); }}; This is in MENU.js: var stateMENU = { create: function(){ game.stage.backgroundColor = "#8A8A8A"; var spaceBttn = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceBttn.onDown.add(this.start,this); }, start: function(){ console.log('start'); this.game.state.start('play'); }};This is in PLAY.js: var bgColor = "#678543";var statePLAY = { create: function(){ console.log('CREATE'); game.stage.backgroundColor = bgColor; var moveKeys = game.input.keyboard.createCursorKeys(); }};^ When you hit spacebar during the 'play' phase, it triggers the code in the start function in stateMENU and the console logs 'start' along with 'create'. This is in GAME.js: var game = new Phaser.Game(600,400,Phaser.AUTO,'gameDIV');game.state.add('load',stateLOAD);game.state.add('menu',stateMENU);game.state.add('play',statePLAY);game.state.start('load');