When I port between Desktop games and Mobile games, I find I always make a kludge out of the interaction events.

I typically end up hard-coding event handling for mobile, and event handling for the desktop in completely separate systems.

On mobile, I need to track multiple touches.

On desktop, I only have a single mouse pointer.

But on desktop, there is a concept of "hovering" above something with a mouse. There is no such thing on mobile. Or pressing a modifier key like SHIFT or CTRL while clicking a button or pressing a key.

I want to design an API that I can use on both mobile and desktop that is able to translate an interaction (by user) to an action in my game world.

Are there any design patterns that I can follow, or some abstract model I can use for this? How do people successfully marry the desktop and mobile port of a game?

So in the same code-base, maybe assign Alt+Left-Click to a certain game function, but on mobile have that done via a gesture.

On Desktop, I currently use SDL2's SDL_Event. On Apple, is use UIEvent, and on Android I use NDK's AInputEvent.

  • 1
    \$\begingroup\$ This is kind of a link and opinion based question/answer, so idk if it's appropriate to answer it in answers. I would suggest going with Command pattern and mapping different input types to commands. Then if possible is to have a platform-dependent compilation to avoid having ifs for every type of device input. \$\endgroup\$ – Candid Moon _Max_ Nov 4 '19 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.