O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition 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

Adding a directional pad

Directional pads are used mainly in RPGs, where full 360-degree movement of the player is required. Also known as a D-pad, it sits in the lower-left corner of the screen, and once the player puts their finger on it and moves the finger in the direction that they want the player to move in, the character will start moving in this direction.

Getting ready

We will create a new class called DirectionalPad for this. So, let's start creating it. Also, we will comment out or delete the code related to the accelerometer but keep the accHero sprite as we will need it for this section.

How to do it…

In the DirectionalPad header file, we will add the following:

#import "CCSprite.h" #import "cocos2d.h" @interface DirectionalPad :CCSprite{ ...

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