Game Development Reference
In-Depth Information
-(id) init
self = [super init];
if (self)
const int borderSize = 10;
playableAreaMin = CGPointMake(borderSize, borderSize);
playableAreaMax = CGPointMake(tileMap.mapSize.width - 1 - borderSize, ←
tileMap.mapSize.height - 1 - borderSize);
return self;
The playable area is defined as anything within the bounds of the tile coordinates
(10, 10) to (39, 39) . All tiles outside this area should be considered not part of
the playfield. All that remains is to update the tilePosFromLocation method by
replacing the MIN / MAX lines to implement this rule of the playable area. Instead of
keeping the tile coordinates within the bounds of the whole tilemap, you now want to
keep it within the bounds of the playable area, as such:
posX = MAX(playableAreaMin.x, posX);
posX = MIN(playableAreaMax.x, posX);
posY = MAX(playableAreaMin.y, posY);
posY = MIN(playableAreaMax.y, posY);
If you try this, you'll see that only the tiles within the playable area can be centered on-
screen. What's more, clicks outside the playable area aren't just ignored; the tilemap
scrolls as close as possible to the tile you clicked. This way, you don't destroy the play-
er's impression of a world that seemingly extends far beyond what the player can see.
Adding a Movable Player Character
By adding a player character moving about the tilemap world, you get closer to an ac-
tual isometric game. In this case, I chose ninja.png as the player character and ad-
Search Nedrilad ::

Custom Search