iPhone Game Programming – Tutorial 6 – Tiled Map Class

The next installment of the 71Squared iPhone Programming tutorials is now available. This tutorial covers a tile map class which can consume configuration files created using the Tiled map editor.
The Tiled editor can be found here.

Tile maps allow you to create large images or playing areas within your game using smaller tile images. Rather than have a large single background image, you create your background by using smaller tile images placed together.
There is no reason why this could not be as simple as an array which holds the x and y location within a tile map and for each given location an id is stored which identifies the tile to be rendered for that tile in the map. This is basically how the Tiled class works. The only difference is that the Tiled editor allows you to have multiple layers and tilesets in a single map along with user defined properties.
Once you have created your map using the Tiled tool it saves the map as an XML file. This XML file along with the spritesheets that was selected for your tilesets can then be copied into your iPhone project and referenced using the TiledMap class.
Tile maps are useful in a number of areas. Not only can they let you create very large playing area within your game from a number of small images, but it can be used within collision detection. You can easily work out which tile the player is within on the tile map and also for all the baddies. You can then only check for a collision between the player and baddies who are in the adjacent tiles reducing the number of collisions checks which need to be done.
As usual the Tutorial 6 project has been posted below as well.


Play Tutorial (1:35:17)
Tutorial 6 Project
I hope you enjoy this tutorial. As always feedback and comments are welcome and I hope to have the next tutorial on the Particle System up as soon as possible.
Mike

Comments