Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSimonForsman

Posted 19 April 2013 - 04:10 AM

the left edge of the camera is at: camera_offset_x - camera-view-width / 2 and the right edge at camera_offset_x + camera_view-width / 2 right ?

(and similarily for the top and bottom edges)

 

If so then:

 

Edit: This assumes the camera position is the center of the screen (skip the -cam_width|cam_height /2 and change +width|height / 2 to just +width|height if the camera position is the top left)

firstcolumn =  floor((camera_offset_x - camera_view_width / 2) / tile_width)

lastcolumn = ceil((camera_offset_x + camera_view_width / 2) / tile_width)

firstrow = floor((camera_offset_y - camera_view_height / 2) / tile_height)

lastrow = ceil((camera_offset_y + camera_view_height / 2) / tile_height)

 

 

 

Now, assuming there are no gaps in your tile array and it is layed out row by row (so the first row comes before the 2nd row in the array etc)

If your tiles are stored in a random order you should change how they are stored.

 

firsttile = firstrow*tilemap_columncount + firstcolumn

lasttile = lastrow*tilemap_columncount + lastcolumn

 

iterate over that range


#1SimonForsman

Posted 19 April 2013 - 12:47 AM

the left edge of the camera is at: camera_offset_x - camera-view-width / 2 and the right edge at camera_offset_x + camera_view-width / 2 right ?

(and similarily for the top and bottom edges)

 

If so then:

firstcolumn =  floor((camera_offset_x - camera_view_width / 2) / tile_width)

lastcolumn = ceil((camera_offset_x + camera_view_width / 2) / tile_width)

firstrow = floor((camera_offset_y - camera_view_height / 2) / tile_height)

lastrow = ceil((camera_offset_y + camera_view_height / 2) / tile_height)

 

Now, assuming there are no gaps in your tile array and it is layed out row by row (so the first row comes before the 2nd row in the array etc)

If your tiles are stored in a random order you should change how they are stored.

 

firsttile = firstrow*tilemap_columncount + firstcolumn

lasttile = lastrow*tilemap_columncount + lastcolumn

 

iterate over that range


PARTNERS