Advertisement

Good way to create isometric tiles...

Started by December 30, 2000 03:42 PM
8 comments, last by caesarweb 24 years ago
Probably lots of you already know this method but it''s good to try it, especially for NewBies like myself. I''m talking about an isometric tile array. Actually its a little bit more complicated. I have developed one of these in VisualBasic but I think there is no problem in adapting it on VisualC++. Ok, what I do is this: First, I create a new type, called for example IsometricMap. I make it with four important properties: Top, Bottom, Left, Right, just like a rectangle. Then I declare an array of this type, something like DIM IsoMap(20,20) as IsometricMap Then, in my game, I have a for cycle which attributes the coordinates to each variable in the IsoMap(20,20) array. After I do this, in another FOR cycle, I start blitting the map on a surface, the dimensions are already set, I just have to apply dimensions to a Rectangle which I use for blitting. You must be asking why I don''t use an array of rects. The answer is that you can add a little bit more properties to this type, like a boolean variable named collision, or xpos and ypos variables to determine the world position. Thus I think this solution could be helpful. Comments, suggestions, please reply. Caesar
A young man with lots of talents
Anyone?
A young man with lots of talents
Advertisement
If I understand you correctly you are giving each tile type properties for where it is going to be drawn (like for the first tile you would have top=0,left=0, right=width of tile, bottom=height of tile) so when you blit you use these properties as coordinates on the destination surface to blit to. Is this correct?
If I am right in thinking this then personally i think it is a decent way of doing it. I generally use 2 for loops starting at 0 for x coord then moving tile width across and draw another until it gets to the end and then go back to x=0, y=1. this way my tile class doesnt need the coordinates for where it is going. I dont actually see why one way would be better than the other way but then i am also a newbie.

Just my thoughts take them as you will.

"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
What I do is I just have an array of tiles, and then when I''m drawing the map I use a function to figure out what tile the current location I''m blitting at should be. This is in C++, but it''s adaptable to visual basic.

The method I use:

MapX = xViewPos + ScreenX + (ScreenY >> 1);
MapY = yViewPos + (ScreenY >> 1) - ScreenX;

if(ScreenY % 2) MapX++;


xViewPos and yViewPos indicate the location of the current viewing area since the map is bigger than one screen. ScreenX and ScreenY indicate the coordinates of the location on the screen that the tile for is needed.
First I must say that Zeke understood my method.
OK, Zeke I must say that I have used your method. Exactly two FOR cycles where each tile is blitted. But then you might have a problem. How do you detect collision. You could have something like an array of collision rects, but that can be hard, real hard. I''ve tried it myself. Anyway, if you work in C++ maybe its easier for you. As for Pyro, his method is as good.
A young man with lots of talents
Sorry, but I don''t think this is very effective for your typical tile-based game. Why? Because I can''t imagine a situation where you have a tile object and need to know where on the map it is. Usually you have a coordinate on the map and need to know what type of tile you can find on it (i.e. is it passable, what image should you use to draw it). So you''re just using up unneeded memory. In your standard tile-based game you have big maps - up to 128x128, maybe even more, so this is an issue: First of all you''re wasting space, second it reduces the fraction of the map that can be cached in the on-board caches during loops across the map.

In fact, using a tile class or type in the OOP isn''t a very good idea at all. They''re just using up space with VMTs etc.. Okay, they don''t necessarily do - you could create a class that takes up only 4 bytes, but then what''s the point in creating a class when you''re not using inheritance (which would require another 4byte VMT).

cu,
Prefect
Widelands - laid back, free software strategy
Advertisement
Oh, you''re right, but I don''t think I''ll use maps so large
A young man with lots of talents
For my iso engine, i use a class called TILE
and then make a 2D array of it like
TILE tile[128][128];

In my tile class, (I cant give out specifics) but it contains 26 float variables, 11 intergers, a couple booleans and linked list of units on the tile. That is all stored in every tile, and I had once tested a map of size 1000x1000 tiles and it didnt slow down by even a single frame per second. The contents of your tile array can and probably should store lots of info and you dont need to worry about memory. When you have a complex game like Alpha Centauri, the tiles have to store a boat load of information, so dont be all paranoid about memory usage. Memory is cheap so dont be afraid to use it (75dollars for 256meg dim of PC133 right now!).

Possibility

Edited by - Possibility on January 7, 2001 11:58:02 PM
Wow, what kind of game are you writing? All the info I have on a tile fits into 4 bytes, not including unit lists.

I have to disagree with you on the "memory is cheap" thing though. This is the kind of attitude that brought us 30MB word processors, where 10 years ago 64KB were enough. I think for every game you always have to consider optimization as early as possible. Even the reorganization of small structs can change the world. I once had a small&stupid Game of Life simulation which initially had problems with non-cache-aligned data. After fixing this simple problem, I had a speed increase of over 300%. Now we weren''t talking about cache-aligning right now, but I think you get the point.

cu,
Prefect
Widelands - laid back, free software strategy
I calculated my tile memory usage, each one uses about 228 bytes. If your working in 3D as i am, you need a vertex point for each corner, and each vertex (d3dvertex) is 8 floats (32 total floats for the 3d coordinates of each corner), and then i also have a material for each tile (d3dmaterial7) which is 17 floats. Plus then you need information on what type of tile it is, what bonuses the tile has, what enhancements are built on it, is there a city on it, any structures, farms, roads, mines, any spells cast on the tile, any units located on it, ect...

Possibility

This topic is closed to new replies.

Advertisement