
One way consists of drawing the section that will be visible off-canvas (instead of the entire map.) That means that as long as there is no scrolling, the map doesn't need to be rendered.Ī caveat of that approach is that when there is a scrolling, that technique is not very efficient. Of course, if the map is large this doesn't really solve the problem - and some systems don't have a very generous limit on how big a texture can be. One simple technique consists of pre-rendering the map in a canvas on its own (when using the Canvas API) or on a texture (when using WebGL), so tiles don't need to be re-drawn every frame and rendering can be done in just one blitting operation. The first approach, as discussed above, is to only draw tiles that will be visible. Usually, some techniques need to be implemented so scrolling can be smooth.

The tile atlasĭrawing scrolling tile maps can take a toll on performance. Think about any game that uses regularly repeating squares of background, and you'll probably find it uses tilemaps. Some popular games that use this technique are Super Mario Bros, Pacman, Zelda: Link's Awakening, Starcraft, and Sim City 2000. This set of articles covers the basics of creating tile maps using JavaScript and Canvas (although the same high level techniques could be used in any programming language.)īesides the performance gains, tilemaps can also be mapped to a logical grid, which can be used in other ways inside the game logic (for example creating a path-finding graph, or handling collisions) or to create a level editor. This results in performance and memory usage gains - big image files containing entire level maps are not needed, as they are constructed by small images or image fragments multiple times.
Tilemaps are a very popular technique in 2D game development, consisting of building the game world or level map out of small, regular-shaped images called tiles.
