Jump to content

Phaser Instructions State help!


effin_drwg
 Share

Recommended Posts

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..

 

Boot

Load

Menu > Instructions (NEW)

Play

Game

var 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

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

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 use

this.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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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