A flexible, extensible game input system (PG)

I’ve been working on a project (ok, a game!) that of course involves being able to accept different types of input from different devices. Naturally, I started by putting together a PG to test out and quickly iterate my code. Here’s the result:

Controls:
W, A, S, D - move left, right, up, down
Shift, CTRL - move in/out
Arrow keys - rotate
Enter, Click, Tap, X (gamepad), Start, etc - Change color of box to random color

Game Input System

It’s pretty basic, but I hope it demonstrates to the community how you might approach being able to do things like this. The final code for my project is pretty close to this, but with a number of important differences having mostly to do with Scenes needing to co-habitate in the same application nicely (I still haven’t solved some problems to my satisfaction - specifically including support for debouncing).

If you’re curious, you can look at where the various pieces of the PG ended up in the code here.

LMK if I can answer any questions!

HTH

ed: silly me, forgot to mention – this supports Keyboard, Mouse, Touch, and Xbox gamepads

8 Likes

finally someone has done a piece of engineering work and centralized the input options. this class should definitely be adopted in the basics.

great work, jelster! :slight_smile:

Unfortunately, you don’t get an award, but a handful of shining sparkling stars. :smiley:

2 Likes

This is awesome, a clean deadzone setting would be awesome too!

2 Likes

Thanks for the feedback and the support!

When you mention a clean dead zone setting, do you mean a user-configurable dead zone setting? The utility functions that map Rptation/Translation into actions have a built in threshold for triggering, which is kinda like a dead zone, but what is it missing?

So for touch events only Tap is supported?

Did someone created a controller for an mobile accelerometer? This would be a cool 3D “mouse” controller! :slight_smile:

Right now, yeah, tap is all that I implemented for this PG. You can add additional gesture handlers quite easily though - I’d love to see if it’s as painless in practice as I hope it is in theory! :sunglasses::grin:

If I’ve done my job right with this, then it should be straight-forward to add accelerometer support - I would start by stealing researching the DeviceOrientationCamera code :slightly_smiling_face:

2 Likes