# Algorithm Help

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

## Recommended Posts

Not sure if it's just because I'm up too late, or if I really need help; I'm having a bit of trouble building an effecient algorithm to properly draw my isometric tiles in order. I've made a little chart to help explain: The tiles are in a simple 2D array, rotated 45 degrees clockwise, and can have any bounds for the tips of the diamond. For this example, I'm trying to find an algorithm that will make the draw order: 0,0 0,1 1,0 0,2 1,1 2,0 1,2 2,1 2,2 Thanks for any suggestions, or a link in the right direction! Cyric

##### Share on other sites
I can see two solutions:

- data-based algorithm:

positions = { (0,0), (0,1), (1,0), (0,2), (1,1), (2,0), (1,2), (2,1), (2,2) }foreach(pos in positions) render( pos );

- depth-based algorithm:

renderLine (depth) =  start = 0;  end = depth;  for(i = start to end) render( i, depth - i );for(i = min to max) renderLine( i );

Adjust start, end, min and max so you only render tiles on the screen.

##### Share on other sites
Here goes -

#define YTop    0#define YBottom 2#define XLeft   0#define XRight  2int i, y, x;// The diagonals starting on the left edge for (i = YTop; i <= YBottom; i++){    for (y = i, x = 0; y >= 0; y--, x++)    {        DrawTile(x, y);    }}// The diagonals starting on the bottom edge (except for the left one drawn earlier)for (i = XLeft+1; i <= XRight; i++){    for (x = i, y = YBottom; x <= XRight; y--, x++)    {        DrawTile(x, y);    }}

##### Share on other sites
I'm moving this to the Isometric Land forum. Isometric algorithms are practically their bread and butter.

##### Share on other sites
Worked perfectly, thanks a ton guys!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 16
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015497
×