Texturing 2d tile map

Started by
1 comment, last by Prodigal Squirrel 18 years, 1 month ago
I was curious of what strategies are use for texturing a 2d tile map. Currently, I assumed to just give each visible object an image variable, that is assigned a certain graphic file. Is this a valid strategy, or are there more efficient approaches to texturing a 2d tile map?
-------------------------- Alex--------------------------
Advertisement
Let's say you store your map as a 2d array.

One method, like you said, is to give each tile its own image. That would work, but it's slow, and it's a massive waste of memory. (100 tiles might share the same image) Another method is to give each tile a pointer to whatever texture it is drawn with. It's good on memory, but when you go to save your map to disk, you can't save a bunch of pointers and expect them to still be valid when you start up.

A third method, and IMO the best and easiest, is to have each tile store an integer, which will act as a texture index. In your drawMap function, the function would look up each tile's index in, say, a vector of images and draw that one. That's the method I used for SDL stuff back when I used it.

Now, that's good, but looking up a pointer to an image inside a vector can take enough time to slow you down if you're drawing a lot of tiles. A more advanced implementation is to use both the second and third method: Keep an array of integers so you can save the map to disk, and when it loads, fill a second array of pointers to the actual texture. That way when you're drawing you can just grab the texture pointer right from the map array, instead of using a vector lookup.
"ok, pac man is an old gameand, there are faces which is eatin up shits" - da madface
Quote:Original post by Foobar of Integers
In your drawMap function, the function would look up each tile's index in, say, a vector of images and draw that one.


Thanks for the help, and I like how used drawMap as an example since it has the exact same notation and name as the map drawing function in my engine.

-------------------------- Alex--------------------------

This topic is closed to new replies.

Advertisement