Game Development Reference
In-Depth Information
The gist of the work has now been moved to the update method, which is scheduled
to be called every frame:
-(void) update:(ccTime)delta
CCNode* node = [self getChildByTag:TileMapNode];
NSAssert([node isKindOfClass:[CCTMXTiledMap class]], @"not a CCTMXTiledMap");
CCTMXTiledMap* tileMap = (CCTMXTiledMap*)node;
// if the tilemap is currently being moved, wait until it's done moving
if (tileMap.numberOfRunningActions == 0)
if (currentMoveDirection ! = MoveDirectionNone)
CGPoint tilePos = [self tilePosFromLocation:screenCenter tileMap:tileMap];
CGPoint offset = moveOffsets[currentMoveDirection];
tilePos = CGPointMake(tilePos.x + offset.x, tilePos.y + offset.y);
tilePos = [self ensureTilePosIsWithinBounds:tilePos];
[self centerTileMapOnTileCoord:tilePos tileMap:tileMap];
// continuously fix the player's Z position
CGPoint tilePos = [self floatTilePosFromLocation:screenCenter tileMap:tileMap];
[player updateVertexZ:tilePos tileMap:tileMap];
The tilemap has a running action only when it is moving, so I give it a new move ac-
tion only if it has no move action currently running and the currentMoveDirec-
tion isn't MoveDirectionNone . The tilePosFromLocation is no longer re-
trieved from the screen touch location, but instead the screenCenter position is
used. Since the player is always centered on the screen, this is a convenient shortcut to
the tile coordinate at the center of the screen.
The moveOffsets array returns a CGPoint that is added to tilePos to get the
new tile coordinate we intend to move to. Because this can be outside the playable
Search Nedrilad ::

Custom Search