Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
1  
Duh, wow, I need coffee I guess, thanks –  Ilya Oct 13 '10 at 18:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.