What are the math for tile detection on a 2D isometric layered diamond shaped map ?
Here is an image of a layer (this is an image from an old folder, I didn't write the display yet for my current project, so it's incomplete but you get the idea) :
I have them staggered on top of each other. Tile detection could works with a loop but it would take too much time. The basic math for floor tiles doesn't work.
A layer is composed of a tiles(array) :
A tile_size * tile_size image representing a 3D square.
A long time ago I asked this question with an account I'v lost unfortunatly and I had one answer :
- Create an hollow ground
But I never understood what that was and when I type "tile detection hollow ground" on google, I got nothing.
I also found several solution I do not understand the concept :
Ray scan on neightbours (I know the theory for ray scanning, but neightbours ??? All of that sounds very difficult for me)
using color mask for a pixel perfect detection (no time to implement such a method)
So, was left the math. And here I'm stuck. I'm looking at my formula 'isometric to screen' conversion(for display), hoping a miracle ha ha :
int x = (i - j) * TILE_SIZE_HALF, y = (i + j) * TILE_SIZE_QUARTER - (layer_id * TILE_SIZE_HALF); //This one is totally working
Anyway, is there even a formula able to solve tile detection for such a map ? Am I missing something ?
What I'm looking for :
//With given x & y (mouse coordinates on screen) int i = ?, j = ?, layerID = current_layer_index, //tile's index in tile array(layers are tile arrays) : tileIndex = calculated from I & J; //Where goes the offsets in these calculations ?
How am I gonna know which layer the tile is from ?
I decided to only edit the selected layer (current_selected_layer variable) and then check if the tile is empty. If yes, I'll select the "same tile" but the layer under the selected one and so on. Now the problem should be less complicated since it's like there is only one layer. What bother me are the map offsets.
EDIT : I didn't tought about the corner... This is not gonna work. If I don't find a solution, I'll maybe switch to classic 2D. Sounds very complicate to code tile selection with isometric map.
There is another problem I have no idea how to handle these :
(this is a layered map, the screen do not represent the final result)
End note: Pseudo code is welcome. Also, consider you have all informations about the map. Since I use a pseudo MVC code, I have access to all data everywhere (tile size, layers number, etc...). There is no restriction.