O'Reilly logo

Learning Cocos2d-x Game Development by Siddharth Shekar

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

Movement with touches

Now, using touch, we move the player to the touched location on the screen.

To do this, we use CCActions. CCActions are predefined classes of Cocos2d-x that can be used to perform various functions on an object over a period of time.

We can also combine multiple actions together to perform actions one after the other using CCSequence. Let's first see how to make the player move from the initial position to the desired touch location. Also, to ensure that the character doesn't simply go from point A to B, we add an easing action that will slowly increase the speed of the character when starting. When reaching the destination, it will slowly decrease the speed and bring the character to a halt.

To do this, we have to get the location ...

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