Tiled
TiledMaps are widely used in 2D game development. TiledMaps build up the game world from small images, called tiles. This leads to better performance and less memory usage. Because you don't need large-scale image files to render your map.
#
ToolsFor creating TiledMaps, I recommend Tiled. Tiled is a free and open-source, easy-to-use, and flexible Tile editor.
For drawing tilesets, you can use the following tools.
Tool | Price |
---|---|
Aseprite | Paid (unless you compile it yourself) |
Libresprite | Free |
Pyxel Edit | Free |
Krita | Free |
info
The assets from this example can be downloaded here.
#
Example#
LoadingYou can load a TiledMap using the Content.LoadTiledMap
method.
#
RenderingFor rendering the tiledmap, you can use the TiledMapRenderer
component.
By default the TiledMapRenderer
renders all layers, you can set these yourself with SetLayersToRender
.
SetLayersToRender
does not adjust the render order. For that, you need to use multiple TiledMapRenderers
with different RenderLayers
#
MaterialsYou can also use Materials
with TiledMapRenderer
. Check out the Stencil docs on how to add stencil shadows to your TiledMap.
#
CameraAdding a camera is very simple. First we need to define the boundaries of our camera, using the tiledmap size.
Finaly we add an entity that will be tracked by our camera.
#
CollisionCollision is very easy to add by assigning a TiledMap layer as a collision layer. All non-empty tiles in this layer will then act as colliders.
For convenience, I'll use the water layer. Since the water layer also has non-empty tiles under the bridges, we can unfortunately no longer use them.
And we wrap this up by adding a BoxCollider
to our Character
.