# Drawing a 2D tile based map

**URL:** https://discourse.processing.org/t/drawing-a-2d-tile-based-map/12101
**Category:** Coding Questions
**Created:** [June 16, 2019, 7:39pm UTC](https://discourse.processing.org/t/drawing-a-2d-tile-based-map/12101 "2019-06-16T19:39:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)
#### Post date: [June 16, 2019, 7:39pm UTC](https://discourse.processing.org/t/drawing-a-2d-tile-based-map/12101/1 "2019-06-16T19:39:23Z")

</div>

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](https://discourse.processing.org/t/hiscapes-roast-my-game/12082)

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [June 17, 2019, 10:54pm UTC](https://discourse.processing.org/t/drawing-a-2d-tile-based-map/12101/2 "2019-06-17T22:54:51Z")

</div>

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/](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.

---

<div class="post-metadata">

### Author: ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)
#### Post date: [June 18, 2019, 12:13am UTC](https://discourse.processing.org/t/drawing-a-2d-tile-based-map/12101/3 "2019-06-18T00:13:10Z")

</div>

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