Game Development Reference
In-Depth Information
moving toward, and you need a scheduleUpdate to continuously check whether
the player still wants to move.
The ccTouchesBegan method ( Listing 11-8 ) has changed to simply check which
quadrant of the screen received the touch and then sets the currentMoveDirec-
tion . The newly added ccTouchesEnded method sets the currentMoveDir-
ection back to MoveDirectionNone .
Listing 11-8. Moving the Player Based on Touch Location
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// get the position in tile coordinates from the touch location
CGPoint touchLocation = [self locationFromTouches:touches];
// check where the touch was and set the move direction accordingly
if (CGRectContainsPoint(upperLeft, touchLocation))
{
currentMoveDirection = MoveDirectionUpperLeft;
}
else if (CGRectContainsPoint(lowerLeft, touchLocation))
{
currentMoveDirection = MoveDirectionLowerLeft;
}
else if (CGRectContainsPoint(upperRight, touchLocation))
{
currentMoveDirection = MoveDirectionUpperRight;
}
else if (CGRectContainsPoint(lowerRight, touchLocation))
{
currentMoveDirection = MoveDirectionLowerRight;
}
}
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
currentMoveDirection = MoveDirectionNone;
}
 
 
Search Nedrilad ::




Custom Search