Game Development Reference
In-Depth Information
EMoveDirection currentMoveDirection;
The EMoveDirection enum is later used to determine in which direction the play-
er intends to walk, with MoveDirectionNone signaling no movement. Let's look at
changes in the implementation of the TileMapLayer class's init method in List-
ing 11-7 .
Listing 11-7. Initializing the Player's Movement Directions
// divide the screen into 4 areas
screenCenter = CGPointMake(screenSize.width / 2, screenSize.height / 2);
upperLeft = CGRectMake(0, screenCenter.y, screenCenter.x, screenCenter.y);
lowerLeft = CGRectMake(0, 0, screenCenter.x, screenCenter.y);
upperRight = CGRectMake(screenCenter.x, screenCenter.y, screenCenter.x,←
lowerRight = CGRectMake(screenCenter.x, 0, screenCenter.x, screenCenter.y);
moveOffsets[MoveDirectionNone] = CGPointZero;
moveOffsets[MoveDirectionUpperLeft] = CGPointMake(−1, 0);
moveOffsets[MoveDirectionLowerLeft] = CGPointMake(0, 1);
moveOffsets[MoveDirectionUpperRight] = CGPointMake(0, -1);
moveOffsets[MoveDirectionLowerRight] = CGPointMake(1, 0);
currentMoveDirection = MoveDirectionNone;
// continuously check for walking
[self scheduleUpdate];
The four CGRect variables, upperLeft , lowerLeft , upperRight , and
lowerRight , divide the screen into four quadrants, each of which is the touch area to
move the player in the desired direction. Thus, a touch in the lower-right area of the
screen will move the player to the right and down along the tilemap.
The moveOffsets array contains a CGPoint for each move direction that, when
added to the current tile coordinate, will return the next tile coordinate in that direction.
The currentMoveDirection variable simply holds which direction the player is
Search Nedrilad ::

Custom Search