O'Reilly logo

Building Android Games with Cocos2d-x by Raydelto Hernandez

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

Chapter 4. User Input

So far, we have added the graphics that move around the screen and collide with each other, but it is not fun yet, since the player cannot control our main character and it would not be a game unless our user can interact with it. In this chapter we will add user interaction to our game. The following topics will be covered within this chapter:

  • Understanding the Event Dispatcher mechanism
  • Handling the touch event
  • Handling the accelerometer events
  • Keeping the screen alive
  • Handling the Android back key pressed event

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

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