• Create Account

### #ActualBacterius

Posted 24 August 2012 - 10:03 AM

Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile in each row to be shown on the screen!" and so forth. You can actually also calculate quickly which tiles are the "boundary tiles" with a formula if your tiles are all the same size, but it's best you try and do it the explicit way first so you don't get confused.

Does it make sense?

### #3Bacterius

Posted 24 August 2012 - 10:02 AM

Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile in each row to be shown on the screen!" and so forth. You can actually also calculate it quickly with a formula if your tiles are all the same size, but it's best you try and do it the explicit way first so you don't get confused.

Does it make sense?

### #2Bacterius

Posted 24 August 2012 - 10:01 AM

Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile in each row to be shown on the screen!" and so forth.

Does it make sense?

### #1Bacterius

Posted 24 August 2012 - 10:01 AM

Figure out which tile column is the first/last one on the screen and same for tile rows, then only loop across those. You can do this by comparing your tile's positions (top-left corner known from pos and width/height known from TILE_SIZE, which gives you the bottom-left corner) with the bounds of your window. Compare coordinates to do this, e.g. go over a tile row, and go "is the x coordinate less than zero, yes, keep going... yes, etc... ah, this one is more than zero, so this is the first tile to be shown on the screen!" and so forth.

Does it make sense?

PARTNERS