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.
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.
In the DirectionalPad
header file, we will add the following:
#import "CCSprite.h" #import "cocos2d.h" @interface DirectionalPad :CCSprite{ CGPointtouchlocation; CGPointmoveLocation; } @property(nonatomic,assign)float angle; @property(nonatomic,assign)bool touched; @property(nonatomic,assign)float dist; @end
Here, we need to get the initial touch location and then the moved...