Archived

This topic is now archived and is closed to further replies.

How do YOU handle drawing tiles?

This topic is 6387 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just curious what are some of your opinions on how to handle the drawing of tiles. Until recently I had my tile engine doing the standard drawing of the tiles (left to right, top to bottom) that were around the "player". This would occur every frame. This method was pretty fast, but as I decreased the tile size to 16x16 pixels (from 32 x 32) I started to notice a slow down. Now I changed the method so it now renders the whole map to an offscreen surface on initialization, and then blits from that offscreen surface to the backbuffer, the rect area of the player. This method is much faster, since it doesn''t have to do the tile drawing/calculation each frame since it was done on init, but now is this a good method? I''d like to hear everyones opinions . Thanks. Btw, my map size at the moment is 128 x 128 tiles and the tile size is at 32 x 32 pixel.

Share this post


Link to post
Share on other sites
No, I would not recommend that method, mainly because maps often change, and the fact that creating an image several thousand pixels across by serveral thousand pixels in height uses up a tremendous amount of memory. Say for example your map has 5 tiles, each tile is 32x32, so the total area is 5x32x32 = 5120 pixels.
But say you have a mad of 200x200 tiles, then that is 200x200x32x32 = 40960000 pixels. Which is a whole lot larger, thus taking up so much more memory, which is the whole reason why tiles are used. I think the main problem your having is that your computer must be awefully slow. If your computer is getting slowed down just calculating the tiles to place on the screen and calculating there positions, then either you have some incredibly bad arthimitic that is requiring a hundred times more work then nessacary, or you running on a 386 hehe, but even the original Civ worked on a 386 computer.

Also, make sure your back and primary surfaces are in Video memory, and you should have a 4meg video card. Not many people these days have less then a 8meg video card. So I hoped that helped.

Possibility

Share this post


Link to post
Share on other sites
In my tile engine (non-iso), I render the tiles to an off-screen image which is one tile larger in both width and height than the area that I want to display. I then track which tiles are dirty on the map, and only update those tiles. If the visible area scrolls, I repaint the off-screen area. If the new visible area overlaps the old visible area, I scroll the off-screen surface before blitting the "new" tiles. I also keep track of which tile is where on the offscreen surface, so that I can blit only the changed tiles. This can be applied to multiple layers by keeping multiple off-screen surfaces. Another benefit is that I have a "MapView" object which does the drawing, and the tileset to use (as well as it''s dimensions) are attached to the MapView object, not the "TileMap" object. I can then make multiple instances of the MapView object to implement "radar" or minimaps.

I plan on releasing the code (I''m using it in my project Digibot), when I''m done, if anyone is interested. it''s not terribly great code, but it gets the job done. And, if the off-screen view surface fits into vidram (even if all the tiles don''t) it''s DAMN fast (since most scrolling only does one vidmem->vidmem blit, and most modern hardware takes more time to setup a vid->vid blit than it does to actually perform it ;-)



-- Pryankster
(Check out my game, a work in progress: DigiBot)

Share this post


Link to post
Share on other sites
Thanks for your input on this. My (previous) code is probably doing a lot more work than it needs, since my system, well i wouldn''t consider it slow. PII 400 Mhz, 128mb, 32 MB TNT2 Ultra .

I''ll re-look at the previous method and try to check my logic.

Share this post


Link to post
Share on other sites