corey Posted December 21, 2015 Share Posted December 21, 2015 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! Quote Link to comment Share on other sites More sharing options...
corey Posted December 21, 2015 Author Share Posted December 21, 2015 Just saw this topic: http://www.html5gamedevs.com/topic/1922-justpressed-only-once/ I guess I need to find a work around. Quote Link to comment Share on other sites More sharing options...
corey Posted December 21, 2015 Author Share Posted December 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.