Someone asked this in Sina's game production forum, then I will talk about this problem, first look at the map element:
It can be seen that it is a flat rhombus. The size of this map element is 64x32, you can determine the length of the elements at will, when the design program, the map element size is not important, just throw the size into the drawing equation, the program will correctly draw the map. In this example, we first use 64x32 to demonstrate.
So what is this formula? Let's take a look at Staggered Map:
<- staggered
This map has 5 lines, watching this map you will think, how to puzzle the map to spell out. Draw a picture to demonstrate:
As can be seen from this chart, from left to right, from top to bottom, with a regular rectangular puzzle, the same is that there is overlap between the map elements and elements, see the first line and the second line Between, the map element of the second row is pressed on the element of the first row, and the map element of the third line is pressed on the element of the second row. So, just find the correct formula, you can design the program correctly, then come to a picture:
The green spot on the graph (high brightness green, not dark green) is the starting point of each map element, the first line of the coordinates is 0, the second line of the coordinate is 1, the third line of the coordination is 2 ,. ..... Decide the starting point of your map elements from these lines, from this rule to see the position of the position of the line, the landscape of the horizontal coordinate X is 0, line The starting point of the bitmark 1 is to move to the right. Half a map element.
Then find the law from the longitudinal seating, see the lineage of the bit coordinate 0 and the line clip 2, the distance between the two map elements is just a high map element. Again look at the position of the line, the distance between the two map elements is just a high half of the map element. Therefore, calculate the location of each map element, your formula is just:
void CalculateMapTilePos (int n_map_pos_x, int n_map_pos_y, int & n_scrn_pos_x, int & n_scrn_pos_y) {n_scrn_pos_x = n_map_pos_x * iso_tile_size_x (n_map_pos_y & 1) * (iso_tile_size_x / 2); n_scrn_pos_y = (n_map_pos_y) * iso_tile_size_y / 2;}
In this formula, n_map_pos_x is a transverse horizontal coordinate of the map, n_map_pos_y is a longitudinal coordinate of the map, n_scrn_pos_x, and n_scrn_pos_y are the vertical and horizontal coordinations of the map element on the screen.
important:
First, the above formula is only available for Staggered diagonal 45 degree angle map, while Slide, and Diamond-shaped maps, this formula is to be used for a little modification.
SLIDE:
Diamond: