Drawing a 2D tile based map

Hey guys, I have a problem with drawing large tile maps as this has performance issues. Any take’s ? Sorry for the vague description but in a rush. I am talking about a 2D tile grid like showcased with my Hiscapes game demo in my previous post.

RoastMyGame

1 Like

If I read your code correctly, it looks like you are running through every tile in your world and individually testing each to see if it’s on the screen before drawing it. It would be much more efficient to calculate once (each time the view changes) the left, right, top, and bottom tile bounds and then draw the subset of tiles that you then know overlap the screen.

Take a look at https://www.reddit.com/r/processing/comments/aecgdp/using_a_mousebased_ui_to_explore_truchet_tiles/. The draw() method computes the tile bounds based on the current view and renders only the visible tiles.

2 Likes

That is a great idea thanks so much ! Definitely will put you down for credit thanks so much !