Jump to content

Registering one keypress


corey
 Share

Recommended Posts

I'm porting a text adventure game from Unity and I have back to back screens that use the Space bar to advance the story.  This is the statement I'm using for the Unity version in C#:

if(Input.GetKeyDown(KeyCode.Space)){     myStates = States.endgame_1;}

GetKeyDown returns true if the Space bar is pressed/held down. GetKeyDown resets after each frame, so in the next frame if Space is still held down, it won't return true unless it is released and pressed again.

 

Is there a simple way to do this in Phaser that I'm just missing?

 

Please and thank you!

Link to comment
Share on other sites

Found a weird hacky workaround which I'm sure only works for me lol but maybe it'll give someone else some ideas.

 

I had back to back text screens that used Space to move forward so if I held Space down for more than a few milliseconds it would skip right past a screen.  To fix it I created a variable that held the timeDown value of the last key pressed and put that in the Update function: 

saveLastKey=game.input.keyboard.lastKey.timeDown;

Then whenever I ran into back to back screens that used the same key to progress I ran this check on the subsequent screens:

else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)){     if(saveLastKey < game.input.keyboard.lastKey.timeDown)          myStates = States.desk_right;}

To be honest I'm not 100% sure why it works but it does lol.

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