SometimesY Posted June 11, 2016 Share Posted June 11, 2016 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 More sharing options...
rich Posted June 12, 2016 Share Posted June 12, 2016 When the State is changed the Input Manager is reset. Which includes the state of all keys, mouse input, etc. To prevent it you need to set 'resetLocked' to true on the Input Manager (see the docs for more details) Link to comment Share on other sites More sharing options...
SometimesY Posted June 12, 2016 Author Share Posted June 12, 2016 Oh wow. I hadn't even seen this. Though when I went into the Phaser.js and changed it from 'false' to 'true', the issue hadn't resolved itself. Key interruption still seems to be an issue. Link to comment Share on other sites More sharing options...
rich Posted June 12, 2016 Share Posted June 12, 2016 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 More sharing options...
SometimesY Posted June 12, 2016 Author Share Posted June 12, 2016 My bad! I misunderstood. It worked beautifully! Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts