My 2D platformer game is set up where each sector is its own scene. When the player walks beyond the far right edge of scene 1, he ends up at the left edge of scene 2 (like in Metroid and Castlevania games). The problem I’m having is that for each scene, when it’s loaded for the first time, it seems the game doesn’t recognize the controller until a new input is pressed.
For example, I start the game and hold right in scene 1. When I reach the edge and scene 2 is loaded, I’m still holding right on the left control stick, but the player is in idle state, as if nothing is being pressed. Then as soon as I press any button (or move the control stick angle by any amount), the game recognizes the controller and the player goes back to the run state.
The same is true if I am holding left or right as I load the game for the first time, the player just stands there, even though I’m holding a direction.
Any ideas for what I can do to get around this? Players will be annoyed if the character stands still while they hold a direction.
My scenes would be too big if I used them for each “big area”, it would also be a huge structural change.
I tried preserving the gamepad across scenes by setting it as a scene.game property, that didn’t work. When I change scenes the controller just stops responding, as if it needs to be re-initialized each time a scene is loaded. Here’s how I initialize it:
Is there any way to initialize it without using “scene.input”?
Why can’t the game recognize the controller until a new input is pressed after the scene starts?
Why can’t it just tell that the player is holding left or right from the start?
Actually, the same thing happens with the keyboard. I walk into a new scene and the character stands there while I’m holding the left or right key. I logged it and the game recognizes the key as not being pressed in that moment. It’s completely intermittent with the keyboard though, sometimes it recognizes it as being pressed, sometimes it doesn’t.
UPDATE: I found a workaround for the keyboard version of this issue. I just manually set the value of whether the key is down or not based on whether or not it was in the previous scene.