Jump to content
  • Advertisement
Sign in to follow this  
NeilRoy

Isometric tile selection

This topic is 2690 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

I've been working on creating an Isometric editor, mainly just to teach myself how to program Isometrics. So far it's been pretty good, I have a workable editor running and am finally done all the code I needed to get basic editor working, I can add in hills, roads etc... like in SimCity 2000. But now that I am ready to start programming it for layers, like being able to create large hills like in SimCity 2000. in the SC2000 editor you can raise the land up so you have really high hills and it automatically adjusts the terrain around it until you have some pretty large hills.

I have no problem doing that, but, once they are created, how then would you select the tile at the top of the hill? I have code to select tiles on a normal map consisting of one layer, but once the hills get too high, you're pointing in an area that would be mistaken for a normal tile at the base layer under it with my current code. Here's a screenshot to demonstrate...

SC2000.png

Now how would I know that the tile on the top of this hill was for a location closer to the viewer than the tile that exists behind it at a lower level? I've seen lots of tutorials online but none that cover this subject.

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
I'd hazard a guess that one way to do it would be to perform the hit test on each layer one after the other, starting with the highest layer, and stop as soon as a hit is detected. Presumably some kind of spatial partitioning could be employed to speed this process up.

Share this post


Link to post
Share on other sites
One idea I have played with was to do a normal detection, then check the tile's position on screen with the position of the mouse pointer and then just "walk" towards the pointer. If the tile is north of where the pointer is located, than check the tile south, then repeat this until you have a match. I figure you wouldn't have to do much more than a couple tests. And of course, if where you're clicking is a valley instead of a mountain, than the mouse pointer would mostly likely be north of the tile detected on the first pass and you would then walk 1 tile at a time north.

I haven't implemented this yet, but it seems like it might just be the best bet.

Share this post


Link to post
Share on other sites

One idea I have played with was to do a normal detection, then check the tile's position on screen with the position of the mouse pointer and then just "walk" towards the pointer. If the tile is north of where the pointer is located, than check the tile south, then repeat this until you have a match. I figure you wouldn't have to do much more than a couple tests. And of course, if where you're clicking is a valley instead of a mountain, than the mouse pointer would mostly likely be north of the tile detected on the first pass and you would then walk 1 tile at a time north.

I haven't implemented this yet, but it seems like it might just be the best bet.
That's what i would've done too! :)

Imagine raycasting in an isometric perspective. All rays share direction with the general viewing direction:
http://www.flipcode....Structure.shtml
See the wave surfing example near the bottom of the page. If you perform ray/plane intersection like you do now, and then crawl until the examined tile contains the solution
to the ray/tile(plane with limits) -intersection. That would be the selected tile.

Is there anything we cannot use raycasting theory for anyways? ;)

Share this post


Link to post
Share on other sites
Ray casting, yeah, that's actually how I came up with the solution. I was thinking along the lines of raycasting, only I had Wolfenstein style games in mind, so I started to think of how I could apply that idea to Isometrics, and that was when I came up with this. It's not exactly ray casting, but... close enough. ;)

My original idea was to start at the bottom of a map and walk one tile at a time "up" until you reached the right position, al-la-ray casting, that's when it hit me, why not just compare the drawn tile for the detected position with the mouse pointer... I do like it when there's a good programming problem like this. ;)


Edit: Hmmm, I think my "ray casting" from the bottom of the screen may still be the best bet... I still haven't started to program this, I'm too scared to. ;D I probably should though.

Edit2: Ahh, I just checked out that link and I see what you mean about wave surfing. I was just thinking about doing just that when I checked that link out and it was similar. I guess I need to learn to check links sooner . ;)

Share this post


Link to post
Share on other sites
You could have a bitmap layer encoded with the tile's position. When the mouse is clicked you could just look up the encoded information at the mouse coordinate on that bitmap.

Share this post


Link to post
Share on other sites
How are you pushing up terrain, with some sort of Z variable i presume? If you incorporate that Z value within your screen to tile logic you could just iterate through you list or array of tiles and the last hit in that list would be the tile you hovering over since the map is drawn in a back to front order. Must say i just started on my own isometric game and my map is still flat so i'm not sure if it will work.

Share this post


Link to post
Share on other sites

You could have a bitmap layer encoded with the tile's position. When the mouse is clicked you could just look up the encoded information at the mouse coordinate on that bitmap.


I read a book awhile back that suggested doing just this, drawing a second simple version of your isometric map to a secondary surface, each "tile" being its own unique color, then you could do tile selection based on which color pixel you were on top of when the mouse was moved / clicked.

But this limits you to to whatever color depth your using, and the performance problem of drawing another copy of your screen.

Share this post


Link to post
Share on other sites
Another idea I had was to do your normal tile check, but start at the top most layer. You do a check like you would on the base layer of your map. Only for each layer above that you obviously take into account the offset of the tiles in the Y direction. So, you start at the top most layer your map supports, and check the tile at your mouse position on that layer, if there is no tile on that layer, than you check the next layer down and continue this until you run into a tile at that position. This seems to make the most sense to me. You could even have a variable that keeps track of the highest layer that a tile exists on so you wouldn't have to check all the possible layers, only the one starting at the highest layer that is being used and working your way down.

You could even further optimize this by dividing your map into zones, keeping track of the highest layer used in that zone.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!