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: ...
Get Learning Cocos2d-x Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.