effin_drwg Posted November 12, 2014 Share Posted November 12, 2014 I've started a basic game in Phaser, I'm trying to add a feature where you choose to PLAY the game by pressing UP or pressing LEFT to enter the INSTRUCTION state. here's the current layout.. BootLoadMenu > Instructions (NEW)PlayGamevar menuState = {create: function(){//lot more content included in the JS file but this is the function which I've used up to now. var upKey = game.input.keyboard.addKey(Phaser.Keyboard.up); upKey.onDown.addOnce(this.start, this);game.input.onDown.addOnce(this.start, this); }, start: function() { game.state.start('play'); },} Link to comment Share on other sites More sharing options...
effin_drwg Posted November 12, 2014 Author Share Posted November 12, 2014 as you need this in the create function...var upKey = game.input.keyboard.addKey(Phaser.Keyboard.up); upKey.onDown.addOnce(this.start, this);game.input.onDown.addOnce(this.start, this); then you close the brackets on the create function before adding the start function, I don't know where to start to add the LEFT key to take me to the instructions state. HELP!! aha Link to comment Share on other sites More sharing options...
spencerTL Posted November 12, 2014 Share Posted November 12, 2014 Try basing your states on the templates provided with Phaser. The menu state does pretty much what you want except it changes state from a click but that can easily be changed to a key press. I know you've left some code out to show the problem, and maybe you are doing something else that I don't understand but your code diverges considerably from how I understand it works. For eg within your state you use:game.state.start('play');I learned how to use states from the templates and within a state would usethis.state.start('play');to change to the play state. Again, this is something I'm only just about getting my head around but I think you also have some problems with scope. I'd have expected to call this.game.input... rather than game.input. Best advice check the templates!https://github.com/photonstorm/phaser/blob/master/resources/Project%20Templates/Basic/MainMenu.js Link to comment Share on other sites More sharing options...
Recommended Posts