Book Image

Learning Cocos2d-x Game Development

By : Siddharth Shekar
Book Image

Learning Cocos2d-x Game Development

By: Siddharth Shekar

Overview of this book

Table of Contents (19 chapters)
Learning Cocos2d-x Game Development
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Enabling the touch function


The touch function gives us some basic functions; they can be used to create gestures such as TAP, DOUBLE TAP, and SWIPE, which are used in majority of the handheld games these days. Using these functions, we can also create custom gestures depending on the needs of the game.

We can enable touch on a layer by calling the setTouchEnabled() function on the layer and setting it to true so that the layer starts listening to touches; without this, the gestures won't be recognized.

Cocos2d-x comes with the following four functions to create different control schemes:

  • TouchesBegan(): This function is called whenever a finger touches the screen. Whenever a user touches the screen, a tap is triggered. This is one of the easiest gestures to create. Every touch function takes two parameters: the first is a CCSet and the second is a CCEvent. The CCSet is an array that keeps track of the touch count, such as how many fingers are touching the screen. If there are three fingers...