Thinking about input handling
Today over lunch I spent some time thinking about how to approach handling game input across different devices (touch/keyboard+mouse/gamepads).
You can see it here: https://youtu.be/cHhCoqMQ0MA
I was eager to use Combine initially, but quickly realized there's no real need for it.
The gist of the initial approach will be:
- in a base SKScene class all keyboard/touch/gamepad input events will be handled, and mapped to an event of our own type (GameInputEvent)
- the base class will send the GameInputEvent to a method that child-classes will override to handle the normalized events
So it is very similar to how input is handled already in SpriteKit, just with a minimal normalization layer in between.
One thing to note is that it is not enough to just normalize the underlying input events (e.g. gamepad "A" or keyboard "Return" both map to "GameInputEvent.confirm") but we also need to forward some metadata about what originated the event (e.g. keyboard or gamepad, and which gamepad, etc.). This will help us adapt the UI to better match the input device being used.