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

Managing multiple listeners at once


So far, we have studied the two basic mechanisms that Libgdx provides when it comes to handling user input. An event-based approach can be quite useful to respond to certain actions. However, only one InputListener can capture events at a given time.

Often, you will find yourself with two separate subsystems that are interested in different events. Maybe the player input controller, UI system, and game screen all want to be informed whenever the user does something. How will you tackle this limitation then?

You will be pleased to know that Libgdx also comes with a way to achieve this with minimal hassle. Throughout this recipe, we will cover input multiplexing and will have two classes listening to events at once.

Getting ready

For this recipe, it is recommended that you have the sample projects available from the Eclipse workspace.

How to do it…

Take a look at the InputMultiplexerSample class, which looks very similar to the sample from the previous recipe...