There’s an incredibly common, useful design paradigm called ‘target-action’, one I first encountered on iOS. Basically, you’ve got a button that calls a function when something specific happens: maybe a touch or a drag or something. This is the basis of all of iOS’ user input.
So I thought it’d be handy to recreate something similar using the entity-component model. It’s pretty braindead-simple, but it seems to work okay for my purposes. It’s not quite as powerful as it could be, but given that I’ve already put together a game with it, I figure it’s good enough.
Here’s what the component looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
And here’s what using it might look like:
The neat thing, and something I found pretty useful, is being able to rebind your target actions after creation. That ends up looking something like this:
The obvious next step is adding more triggers and actions for various input events. Touch events are a good thing to consider, as well as down-events, too - great for juicy, depressable buttons!