TileMap Class – DONE
HI all, just thought I would do a quick post on Tile Maps. Tile maps have been a part of computer games forever. They allow you to create large images from using lots of smaller images therefore saving memory, but the image they render is only a small part of what they can provide.
A tile map is normally a 2-dimensional array for the X and Y coordinates of the tile map. Information is then help for each tile map location such as the tile to render, if the tile blocks the players movement or causes the player damage when they hit it. Depending on your needs in your game, a tile map is a great tool for everything from collisions detection with the background, identifying points where enemies should be spawned and also feeding into a A* algorithm for path finding allowing enemies to calculate a path around your game world to the player.
Being so important I decided that I needed to create a tile map class as part of the iPhone Game development tutorials I’m writing. I found an great open source tile map editor (Java) here and have written a tile map class which can consume the output from this editor and render it to the screen etc.
I’ll make this one of the tutorials I cover off and I’m sure it will be useful to both me in my continuing work on iPhone Game programming and also to you if your following the tutorials.
Mike
11 Comments
mike on April 6th, 2009
Hi Eskema, your right that there are a number of other mapping tools. TileD is one I’ve used before when developing in Java so I suppose its a case of what you know :)
Having some experience of tiled in Java I wanted to have a go at creating a reader for the tiled format in Objective-C so it really was just personal preference to use it.
I’ve started to write a native OS X tile editor, but that is a long term project for me to learn from and not something which will be finished in time for my tutorials.
I’d be really interested to hear how you get on if you create a reader for another tile map editor.
Mike
Eskema on April 6th, 2009
Actually i use mappy in all my projects, so iphone included ;) .With mappy there are various options, the native format .fmp, the .map format and export as array. I test the native format and find very slow to use in a mobile platform (before iphone i was making games in PSP), so i decided use the speed option, array format. All the maps are exported in array 2d, so like this: int map1[MAPX][MAPY];
Of course with this simplicity you can use the array and create a class to give the values you want to the tiles, you know, doors, water, etc,etc.
Basically you have an array, and do a simple double for to see what number its in the array, and draw the tile associated to this number.
Of course mappy do this number association for you, when you start a project and import the tilesheet, mappy assign each tile image with one position number. So its easy render into screen, and the speed its fantastic :)
If you want i can share my “level” class so you can see how i use the maps, its really easy :)
mike on April 6th, 2009
I’m always interested in seeing other peoples approach to things :) so if you can share that would be great.
From what you have described, does Mappy support things like user defined tile properties, multiple tile sets and multiple layers? They are the kinds of things I normally use.
Do you know if there is a Java version I could run under OS X?
If you want to send me something via email its mike@blog_domain_name.co.uk
Cheers
Mike
Eskema on April 6th, 2009
mappy only works in windows, or linux through wine, i usually do the map work on my laptop with linux ;)
mappy supports multiple layers, but only one tilesheet, of course you can define properties for the tiles. But i use another approach to define tiles properties, im gonna clean a bit my level class and comment it for you
Kenson on April 9th, 2009
Have you guys ever tried cocos2d? It appears to be an open source game engine that is designed for 2D based games. I think they have some tilemapping class but I’ve never used it before, so not sure if it is any good.
mike on April 9th, 2009
HI Kenson
Yes, I’ve seen Cocos2D and had a look through the code base as well. It looks good with some great ideas and concepts on how to get things done. It could end up being something I use, but while I’m learning Obj-C and OpenGL I find that writing my own code really helps that process. I’m a sucker for wanting to know how things work under the hood before I start using them :)
Mike
chris on April 11th, 2009
Mike, I’m finding your tutorials excellent and was wondering where your getting all your info from, experience ? , or are there specific books, articles or sites your reading? If you could share these it would great. I know there are loads of books but some recommendations would really help speed up the process
mike on April 11th, 2009
Hi Chris
To be honest I’m using all sorts of sources to get my info. Some is experience as I’ve been developing software since I was 13 and was writing stuff in Basic on the Sinclair Spectrum 48k :D
My job has moved away from developing software full time although I do still have to get my hands dirty from time to time. All my recent experience has been with Java and that is where the OO side of things has been learnt. As for Objective-C, I’ve only used one book called Cocoa Programming for Max OS X which is a good book.
For the iPhone I’ve just used everything I can find on the Apple website, their examples and as many web sites I can find. I need to put links to some of these sites on the blog which I will get done at some point :)
Some sites I’ve found helpful are:
http://iphonedevelopment.blogspot.com/
http://www.idevgames.com/forum.....y.php?f=66
http://books.google.co.uk/book.....er#PPP1,M1
http://www.anotherearlymorning.....-response/
Check these out and I’ll get all my links I use posted up to the blog asap. Hope this helps.
Mike
gemInEyeTwin on September 21st, 2009
Hello Mike,
Do you know if Tiled supports user defined tile properties?
I liked the multiple layers, but did not see where I could define properties such as animation to play here, sound to play here, object to appear, etc.
Thanks
mike on September 21st, 2009
Hi geminEyeTwin
Yes, TileD does support this kind of information. Rather than assigning properties to a tile which is not possbile, you create an object group layer. Within this group you can then add objects that are pixel based in location not tile based and can also support any number of user defined properties.
In the version of TileD for the tutorials I did not implement the code to parse object layers in the tiled file, but I have added that code to the version of TileD for my book.
The TileD editor is not great at handling objects and so it is common to add and edit objects in the XML rather than through the GUI. A new QT based version of TileD is being written at the moment which is much nicer and handles object groups and objects in a much cleaner way.
Mike




Eskema on April 6th, 2009
There are several tile maps editor better than tiled, i use mappy, and its more powerful, also there are importers in various lenguages (c, c++, delphi,etc) or you can only use the data as an array map[10][10].