O'Reilly logo

Libgdx Cross-platform Game Development Cookbook by Alberto Cejas Sánchez, David Saltares Márquez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required