Wednesday, September 26, 2018

Tile coordinates


Simple question I have here.


Say my tile map is based on 32x32 tiles for an 800x600 image so let's say 25 tiles across and 19 down.


So now I have that cell 0 of any row contains the first 0-31 pixels, cell 1 contains then 32nd-63rd pixels, cell 2 has 64-96 pixels and so on. If I have my player somewhere and now I want to get the corresponding tile, what can I do? I can't just divide by 32 as this doesn't always work such as here:


Let's say I am testing both 64 and 96 in the x direction and am testing against the range of 64-96 (which should be in cell 2 of any row)


64/32 = 2 (this is the correct column for my tile map for any row) 96/32 = 3 (incorrect, the 96th pixel is still within column 2 for any row of the tile map)




Answer



Actually it seems that your calculation is correct - you are just mistaken about pixel 96. Column 3 contains pixels 64-95 inclusive, not 64-96. Dividing by the tile size is in fact the correct method.


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...