Game Development Reference
CGPoint pos = [self floatTilePosFromLocation:location tileMap:tileMap];
pos = [self ensureTilePosIsWithinBounds:CGPointMake((int)pos.x, (int)pos.y)];
With the player now moving across the tilemap tile by tile, we can keep updating the
player's vertexZ value. Previously, the vertexZ value was set to the target tile co-
ordinate immediately, which caused the player to be drawn below all object tiles he
was moving over. By continuously updating the vertexZ value as the player moves
across the tilemap, his z position is now more accurate and removes any overlap
glitches from the previous Iso Tilemap02 project.
Note When you're moving the player through an arc, you'll notice that as he
moves through the arc he'll suddenly appear in front of the arc or disappear be-
hind it, depending on the direction he's moving. This is an unavoidable side ef-
fect of 2D isometric tilemaps. You can reduce this effect only by drawing your
archways higher than any character in your game. You could also split the arc
into three tiles so that only the middle section is passable, whereas the two sides
of the archway are regarded as blocking tiles.
Stop Player on Collisions
Lastly, you don't want the player to walk over walls and mountains. He may be a ninja,
but he's not that good. To solve that problem, add a new layer in Tiled via Layer
Add Tile Layer … and name it Collisions; then move the Opacity slider just above the
Layers list to about the middle. Now pick a tile from the tileset whose color is a strong
contrast to the tilemap, because you'll use it to draw collision areas over the tilemap,
and they should be easily recognizable despite having a low opacity.
I chose one of the purple tiles. Right-click the tile of your choice and select Tile Prop-
erties … from the context menu. Note that this command has no equivalent in the Tiled
menu; tile properties can be accessed only by right-clicking a tile. In the Tile Properties
dialog shown in Figure 11-19 , add a property named blocks_movement and set the
value to 1. Actually, I'm going to ignore the value in code; it's only important that the
blocks_movement value exists.