Friday, June 1, 2018

Calculating the number of tiles shown on an isometric map


I'm currently changing an existing computer game from a top-down view to an isometric view. The map consists of an infinite number of tiles. Only the tiles which are currently visible in the players window should be shown.


What i know is:



  • How many pixels the worldmap has been scrolled on x and y axis

  • The width and height of a single tile

  • The width and height of the players window



What i need to know is



  • The coordinates of the first tile to be shown

  • The amount of tiles that will fit in the players window


To visualize the old approach was something like this (the dashed square represents the players window):


enter image description here


So with the old approach this calculation was pretty simple.


The new one looks like this:


enter image description here



And this is where i'm stuck at the moment. I can't figure out how to calculate which tile is in the upper left corner of the players window and how many tiles fitting inside the players window on the two new axes.


Can anyone help me with that? If yes, it would be really nice if the solution also contains a short explanation.


Thanks a lot in advance.



Answer



If you have a "screen-pixel" to "tile" position function, you could just get the tiles from the 4 corners of the screen and you are done (the green ones in your second image where the dotted line have a corner).


How to do it if you don't?


You might want to check out "Mapping Screen to World Coordinates" here (scroll down a bit)


(fast answer as I'm @ work)


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...