I don't understand why you need to count that in the first place. When you have a tilemap, you should already know how many rows and columns it has. I'll take a guess it's 31x32 because that makes 992 And yes, 992 div 31 = 32, or 992 div 32 = 31, working in both ways. The problem with rendering does certainly not come down to this math, but other code error.