Game Development Reference
In-Depth Information
the GameScene . Then if the touch tapCount is 0 , that is, the user is dragging
the code to move, the player is executed. In this code the tankStat-
sForLocal is updated on the basis of the position of the touch on screen. The
destination is set as the touch location, the direction is calculated by using vector
mathematics using the touch point and the current position of tank. To keep the
direction angle of the tank between 0 to 359 degrees, extra checks should be put
in place once the direction is calculated. After all this, to update the actual posi-
tion and rotation of the tank, a method called updateLocalTank , which we
will be discussing soon, will be implemented.
4. Implement the two other touch methods as well, touchMoved and touchEn-
ded , in GameScene .
5. In touchesMoved , if the game state is kGameStatePlaying then execute
the same code as in touchesBegan method, explained in the preceding point.
- (void)touchesMoved:(NSSet *)touches
withEvent:(UIEvent *)event
{
if (self.gameState == kGameStatePlaying)
{
if([touches count] == 1)
{
UITouch *thumb = [[event allTouches]
anyObject];
CGPoint thumbPoint = [thumb
locationInNode:self];
tankStatsForLocal.tankDestination =
thumbPoint;
tankStatsForLocal.tankDirection = atan2(
thumbPoint.y - tankStatsForLocal.tankPosition.y,
thumbPoint.x -
tankStatsForLocal.tankPosition.x ) - (M_PI/2.0);
// keep us 0-359
if(tankStatsForLocal.tankDirection < 0)
tankStatsForLocal.tankDirection +=
(2.0*M_PI);
else if(tankStatsForLocal.tankDirection >
Search WWH ::




Custom Search