Game Development Reference
In-Depth Information
Tip I'll spare you the details of the mathematical concepts behind this calcula-
tion, because you can apply the code as is and don't need to change anything. If
you're interested in understanding the intricate details of isometric projection
and the mathematics behind it, I recommend reading the excellently illustrated
article by Herbert Glarner at www.gandraxa.com/isomet-
ric_projection.aspx .
By applying the Objective-C MIN and MAX macros, I ensure that the returned tile co-
ordinate is within the bounds of the tilemap. In other words, it will return coordinates
from (0,0) to (29,29) for the 30x30 tilemap used by the isometric tilemap projects.
Scrolling the Isometric Tilemap
With the tilePosFromLocation method updated to work with isometric tilemaps,
the IsoTilemap01 project continues by implementing isometric tilemap scrolling, using
the tile coordinates returned from the tilePosFromLocation method. Just as in
the orthogonal tilemap project, you do this using the center-
TileMapOnTileCoord method, shown in Listing 11-3 .
Listing 11-3. Scrolling the Screen to Center on a Specific Tile Coordinate
-(void) centerTileMapOnTileCoord:(CGPoint)tilePos tileMap:(CCTMXTiledMap*)tileMap
{
// center tilemap on the given tile pos
CGSize screenSize = [CCDirector sharedDirector].winSize;
CGPoint screenCenter = CGPointMake(screenSize.width * 0.5f,←
screenSize.height * 0.5f);
// get the ground layer
CCTMXLayer* layer = [tileMap layerNamed:@"Ground"];
NSAssert(layer ! = nil, @"Ground layer not found!");
// internally tile Y coordinates are off by 1
tilePos.y - = 1;
 
 
Search Nedrilad ::




Custom Search