Book Image

Building Android Games with Cocos2d-x

By : Raydelto Hernandez
Book Image

Building Android Games with Cocos2d-x

By: Raydelto Hernandez

Overview of this book

Table of Contents (16 chapters)
Building Android Games with Cocos2d-x
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding the Event Dispatcher mechanism


Event handling is now different from how it was in the previous version (version 2) of Cocos2d-x. From version 3.0 onwards, we now have a unified event dispatching mechanism, called Event Dispatcher, that handles all sorts of user input events, which may happen during the game.

We can handle many kinds of user input events, such as touches, keyboard key press, acceleration, and mouse motion. In the following sections we will cover how to handle the user input events that relate to mobile games, such as touch, and accelerometer.

There are many classes that allow us to listen for each of the previously mentioned events; once we have instantiated any of these classes, we need to add them to the event dispatcher so, when a user event is triggered, it will call the method defined by its corresponding listener.

You can access the event dispatcher either by the _eventDispatcher instance attribute inherited from the Node class, or by calling the getEventDispatcher...