Jump to content

[Solved] Arrow key is not recognized as being down after changing states


SometimesY
 Share

Recommended Posts

Hi all,

I am making a Zelda-like game and the way I would like to do it is to have every map be separate states (and loaded when walking through passageways). I have the basic game mechanics down but I have a major issue regarding velocities when changing maps (states). What I want to do is have it such that if the player is moving in Level1, say, then the player continues moving into Level2 if the arrow key continues to be held down. If the player walks right through and no other arrow keys are pressed, everything is fine: the state for Level2 recognizes that the arrow key is held down and motion continues. However if I interrupt by pressing any other key on my keyboard after I press the arrow key, when the player enters Level2, Phaser no longer recognizes that the arrow key is held down and so the player does not move. I have to re-press the arrow key for movement to resume. It seems that interrupting with an intermediary key causes Phaser to stop recognizing that the arrow key was held down upon loading the new state for Level2. This is obviously not great since sometimes you might need to adjust your trajectory or fire something at an enemy while moving or even accidentally press a key while moving, any of which will cause a cessation of movement in the next level.

Is there a simple way to fix this? I scoured through this forum and blogs and such, but to no avail. I did notice that you can actually override the truth/falsity of, say, cursor.up.isDown and hardcode it to be a certain value which partially helps, however that's not very satisfactory and has its own serious issues, especially having to do it over many maps with 2-4 passageways each.

Link to comment
Share on other sites

You do it at runtime from your game: 'game.input.resetLocked = true', rather than modify the phaser.js file itself.

Be advised that changing State resets a lot more than just the input though, it resets the physics system, deletes all sprites on the display list, etc.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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