Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 36 ยท 2D and 3D Workflows

2D Workflow - Sprites, Atlases and Tilemaps

Build 2D games in Unity with sprites, pixels per unit, sorting layers, sprite atlases, Tilemaps and Rule Tiles, plus runnable tile and sorting-order stand-ins.

A 2D game in Unity is still a 3D scene: the camera is just Orthographic (no perspective), objects mostly live on the XY plane, and you draw with images called sprites. Choosing the 2D template sets this up, including a separate 2D physics system. This lesson covers the art pipeline: importing sprites, ordering them, packing them into atlases and building levels with Tilemaps.

The Unity setup is shown in text and read-only C#; the runnable blocks are plain C# stand-ins for the data structures involved.

Importing sprites

Drop a PNG into the project and, in the Inspector, set Texture Type to Sprite (2D and UI). Key import settings:

  • Pixels Per Unit (PPU): how many image pixels equal one Unity unit. With PPU 16, a 16x16 tile is exactly 1 unit wide. Pick one value for the whole project so everything lines up.
  • Sprite Mode: Single for one image, Multiple for a sprite sheet that you slice in the Sprite Editor (grid by cell size, or automatic).
  • Filter Mode: Point (no filter) for crisp pixel art; Bilinear for smooth, hand-drawn art. Compression None for pixel art avoids blurry edges.
  • Pivot: the sprite's origin; feet-bottom is better for characters than the centre.

Place a sprite with a Sprite Renderer component. For pixel art, add the Pixel Perfect Camera component to avoid shimmering when the camera moves.

Drawing order

2D has no depth buffer in the usual sense, so the draw order is decided in this order:

  1. Sorting Layer (a named list in Project Settings > Tags and Layers, such as Background, Ground, Characters, Foreground, UI).
  2. Order in Layer (an integer; higher draws later, in front).
  3. For equal values, distance from the camera along the Transparency Sort Axis; for top-down games set it to (0, 1, 0) so objects lower on screen draw in front.
C#
using UnityEngine;

public class DepthSorter : MonoBehaviour
{
    SpriteRenderer sr;
    void Awake() => sr = GetComponent<SpriteRenderer>();

    void LateUpdate()
    {
        // lower on screen = closer to the viewer
        sr.sortingOrder = Mathf.RoundToInt(-transform.position.y * 100);
    }
}
C# Stand-in: sorting layers and order in layer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

The drawing list is printed back to front; the last one printed appears on top.

Sprite atlases and sheets

Every separate texture can cost a draw call. A Sprite Atlas (Assets > Create > 2D > Sprite Atlas) packs many sprites into one big texture so the GPU can draw them together (batching). Add the sprite folders to the atlas, and Unity packs them at build time; your code keeps using the same sprites. Use sprite sheets (one image with many frames) for flipbook animation: select the frames, drag them to the Scene, and Unity builds the animation clip and Animator for you.

Tilemaps

Building a level from hundreds of separate sprite objects is slow and messy. A Tilemap stores a grid of tiles and renders it as a few meshes:

  • Grid parent: defines the cell size and layout (rectangle, isometric, hexagon).
  • Tilemap + Tilemap Renderer children: layers, such as Ground, Walls and Decoration.
  • Tile Palette window (Window > 2D > Tile Palette): pick a tile and paint into the scene, erase, flood fill, box fill.
  • Tilemap Collider 2D + Composite Collider 2D: merge the tile shapes into one efficient collider.

Special tiles save effort: a Rule Tile automatically chooses the right edge or corner sprite based on its neighbours, an Animated Tile cycles frames (water), and a Smart-tile or Tile with a Prefab spawns objects.

The grid is also available from code:

C#
using UnityEngine;
using UnityEngine.Tilemaps;

public class Digger : MonoBehaviour
{
    [SerializeField] Tilemap ground;
    [SerializeField] TileBase dirt;

    public void DigAt(Vector3 worldPoint)
    {
        Vector3Int cell = ground.WorldToCell(worldPoint);
        if (ground.HasTile(cell)) ground.SetTile(cell, null);   // remove
    }

    public void FillAt(Vector3Int cell) => ground.SetTile(cell, dirt);
}

How a rule tile chooses

A rule tile looks at the eight neighbours and picks the sprite whose rule matches. The simplest version uses four neighbours and produces a 4-bit number (a bitmask): add 1 for a tile above, 2 to the right, 4 below and 8 to the left. Sixteen possible numbers map to sixteen sprites.

C# Stand-in: auto-tiling with a 4-bit mask

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Corners and edges receive different characters automatically, just as a Rule Tile would pick different sprites. (The stand-in's art table is intentionally small; ? marks masks it does not cover.)

Parallax, lighting and pixel perfect

For depth, give each background layer a script that moves it slower than the camera, or use Cinemachine's parallax extension. 2D lights from the Universal Render Pipeline (Light 2D: global, spot, freeform, sprite) light sprites that use the Sprite-Lit-Default material and cast Shadow Caster 2D shadows. Normal-map secondary textures give flat sprites volume.

Common mistakes

  • Different PPU values per asset, so tiles do not line up.
  • Bilinear filtering and compression on pixel art (blurry edges or colour bleeding).
  • Moving the camera with a non-integer position on pixel art (use Pixel Perfect Camera).
  • Many separate colliders on a tilemap instead of a Composite Collider 2D.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Pixels Per Unit control?

    It sets the sprite's world size; use one PPU for the whole project.
  2. 2. What is the first thing that decides which sprite draws in front?

    Sorting layer first, then the order inside the layer.
  3. 3. What is a Rule Tile for?

    Rules choose edge, corner or interior sprites so you can paint with one brush.
  4. 4. Why use a Composite Collider 2D on a Tilemap?

    One merged outline is much cheaper than hundreds of box colliders.

Summary

  • 2D uses an orthographic camera, sprites with a consistent PPU and Sprite Renderers.
  • Sorting Layers then Order in Layer decide draw order; top-down games sort by Y.
  • Sprite atlases batch draw calls; Tilemaps with Rule Tiles and composite colliders build levels fast.
  • Point filtering and a Pixel Perfect Camera keep pixel art crisp.

Next: 3D Workflow: Materials and Lighting