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

Character movement


For the character to move at a constant speed over a period of time, we need to basically update the position of the character on the x or y axes, depending on the requirement of the game.

So, to achieve this, we use the scheduleUpdate() function, which is inbuilt in Cocos2d-x. This function will automatically call the update function over and over again, depending on the frames per second (fps) that we set for the applicationDidFinishLaunching() function of the AppDelegate class. If you remember, we the set the frame rate to be 1/60, which is 60 frames per second, so that the update function will also be called 60 times per second.

To include the update function, we go to the init() function and add the following line of code:

this->scheduleUpdate();

This will initialize a regular call to the update function as soon as the scene is initialized. Next, we need an update function.

Creating a function in Cocos2d-x is similar to creating a function in C++. In the .h file of...