Detecting user input via event listening

Rather than asking the input system about the state of a certain peripheral in every single frame, we can let the input system know that we are interested in certain user-generated events and we can get notified whenever they occur. This is known as event listening, and it is better known in the design patterns world as Observer.

Note

It is important to know the most common design patters and when to apply them. To learn more about this topic, we recommend that you take a look at the book Design Patterns: Elements of Reusable Object-Oriented Software, Erich Gamma, Addison-Wesley Professional, or the freely available Game Programming Patterns, Robert Nystrom, Apress (http://gameprogrammingpatterns.com).

Get Libgdx Cross-platform Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.