Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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).

In this recipe, we will tell Libgdx to notify our sample application of the input events and show them all as a list on the screen. Examples of input events are mouse movements, touch dragging, scrolling, touching/clicking, key presses and releases, and...