Hazel

2D Games

The editor has a dedicated 2D view for sprites, tilemaps and pixel art. It has its own camera controls, a grid that can be square, isometric or hexagonal, rulers, guides and snapping made for laying out 2D levels.

Switching to the 2D view

Pick 2D in the viewport header. You rarely need to:

  • Opening a scene picks the view for you. If the scene's camera is a Camera 2D it opens in 2D, a Camera 3D opens in 3D. A scene with no camera opens in 2D when it holds sprites or 2D nodes and no 3D meshes.
  • Selecting a 2D thing switches to 2D. Selecting something clearly 3D switches back.

You can always switch by hand, and your choice sticks until the next scene opens.

To start a 2D scene from nothing, pick the 2D Scene starter that the empty Hierarchy offers. It adds a Camera 2D, so the scene is playable straight away, and switches the view to 2D.

Getting around

ActionHow
PanMiddle-mouse or right-mouse drag
Zoom toward the cursorScroll wheel
Pan up and downShift and scroll
Pan left and rightCtrl and scroll
Frame the selectionF

The Zoom button (the magnifier) in the toolbar has Frame Selection, Frame Game Area, and fixed zooms of 25%, 50%, 100%, 200%, 400% and 800%. Use 100% and above for pixel art: at those steps every source pixel is drawn the same size, which zooms in between do not guarantee. The current zoom shows in the status bar.

Rulers run along the top and left edges, showing world coordinates and tracking your cursor. Your cursor's coordinates also show in the status bar.

The amber rectangle is the game area: exactly what a Camera 2D at the origin shows when the game runs, sized from your project's resolution. World position (0, 0) is its top-left corner. Lay your first screen out inside it and that is what the player sees.

The eye button in the toolbar is the 2D Overlays menu: it shows or hides the Rulers, the editor Gizmos (light markers and selection outlines), Guides, and the physics debug drawing, and has Clear Guides.

The grid

The grid is on by default. The grid pill in the toolbar (a grid icon with a number) shows or hides it in one click, and its number is the cell size in world units. It starts at 16, which matches the default tile size of a tilemap.

The grid draws behind your sprites, and it is faint on purpose so it never competes with your art. Slightly brighter lines mark every eighth cell, and the grid gets coarser as you zoom out so it stays readable. To change its colour and strength, open Settings > Viewport > 2D Grid Color.

The grid's cell size is separate from the move-snap step, so you can change one without the other.

Grid shapes

The dropdown beside the grid pill picks the shape of the cells:

ShapeWhat the cells are
SquareSquares, the cell size across.
IsometricDiamonds the cell size wide and half as tall: the 2:1 shape isometric pixel art is drawn for.
Hex (pointy)Hexagons with a point at the top, the cell size wide, in rows.
Hex (flat)Hexagons with a flat top, the cell size wide, in columns.

Set the cell size to your tiles' width so the lines fall on their edges. The shape also changes what moving with snap on lands on (see Snapping), and it is the shape a tilemap is created with when you drop a folder of tiles (see Tilemaps).

While the grid is isometric the rulers are hidden, because an isometric map's rows run diagonally and screen coordinates do not tell you which tile you are on.

Adding sprites

Drag an image from the Assets panel into the view. A sprite appears where you drop it, already selected, and Ctrl+Z takes the drop back. With snap on it lands on the grid. On an isometric or hex grid it also gets Y Sort set at the bottom of its picture, so furniture placed side by side draws nearest-in-front (see Y Sort).

You can also add an empty Sprite from Add Entity and pick its image in the Inspector.

Selecting and moving

Click a sprite to select it. The click ignores the transparent parts of the image and picks the sprite drawn on top under the cursor. The selection outline follows the shape of the visible picture rather than a rectangle, so a chair is outlined as a chair.

  • Drag the body to move it, drag a handle to resize it, and drag the rotate button (the white icon on an orange disc above the selection) to spin it. Hold Shift while rotating to snap to 15 degree steps, or on a corner handle to keep the proportions.
  • A click that hardly moves only selects, so clicking never nudges an object onto the grid by accident.
  • Shift+Click adds to the selection, Ctrl+Click toggles, and dragging from empty space draws a selection box.
  • Arrow keys nudge the selection. Dragging any one sprite in a multi-selection moves the whole group.

Pixel art (an image drawn with crisp, nearest-pixel filtering, which is how a project's 2D images load by default) gets a frame round what it actually draws and a handle on each corner. Resizing it settles on whole multiples of the picture's size (1x, 2x, 3x, or a half or quarter below 1x) so every pixel stays the same size on screen. Smoothly filtered images get eight handles and stretch freely.

Picking what a click can't reach

  • The Lasso tool (on the tool strip) lets you draw round what you want. It selects everything whose centre falls inside the outline, which is how you pick an irregular patch of painted floor where there is no empty space to start a box.
  • Alt and right-click lists everything under the cursor, top first. Pick a row to select it: the floor tile under a prop, or the lower of two stacked sprites.
  • Locked entities (the lock icon in the Hierarchy) can't be clicked, boxed or dropped onto in the 2D view; clicks go through to what is behind. Locking a tilemap's floor layer lets you work on the props standing on it without grabbing tiles.

Right-click the view for Rename, Duplicate, Group and Delete, the same as in the Hierarchy.

Grabbing with G

Press G with the cursor over the view and the selection follows the mouse without a button held. Click to place it, or press Esc or right-click to put it back. The whole move is one undo step.

Moving along one axis

While dragging, press X or Y to keep the move on that axis, and press it again to free it. A red (X) or green (Y) line shows the axis. Holding Shift keeps the move on whichever axis it is mostly going along. On an isometric grid the axes are the diamond's, so a prop slides straight along a wall.

Snapping

ButtonWhat it does
SnapMoves land on the grid. A dragged sprite's bottom-left corner goes to a grid point, and the rest of the selection moves by the same amount.
Pixel snap (dotted grid)Moves land on whole pixels, so pixel art stays crisp.
Smart snap (magnet)The moved sprite lines up with other objects' edges and centres, and a pink line shows what it lined up with. On by default.

On an isometric grid, a snapped sprite lands on the nearest diamond centre, corner or edge midpoint, so a prop can stand in the middle of a tile or on its seam. On a hex grid it lands on the nearest hexagon centre or corner.

Guides

Drag from the top ruler for a horizontal guide, or from the left ruler for a vertical one. Drag a guide to move it (hold Shift to land it on the grid), and drag it back onto a ruler to remove it. Moving sprites snap to guides. Guides are saved with the project.

Isometric objects

Isometric art packs draw each facing of an object as its own image, named with a letter for the view: Chair_3_A_Tile.png through Chair_3_D_Tile.png. While the grid is isometric, clicking the rotate button turns the selected object to the next facing the pack has, round in order, instead of spinning it. An object drawn from only one side is mirrored instead. Each turn is one undo step.

Selected isometric pixel art is framed as a box standing in the room, fitted to its picture, rather than a flat rectangle.

Measuring and picking colours

The tool strip in the 2D view has two more tools besides the Lasso:

  • Measure (the ruler): drag in the view and a line reads out its length, its x and y spans, its angle and its length in grid cells. Hold Shift to snap both ends to grid corners. Esc clears it.
  • Colour picker (the drop): click anywhere in the view and the colour on screen there goes to every selected object with a Tint or Color field. It turns itself off after one click, and it is one undo step.

Sprite settings

A sprite's look is on its Sprite Image card in the Inspector.

FieldWhat it does
ImageThe picture the sprite draws.
Width / HeightThe drawn size, in world units.
Fit to FrameSets Width and Height to the size of one sheet cell (or the whole image), the pixel-exact size for pixel art.
Flip X / Flip YMirror the sprite. Unlike a negative scale, this leaves children and colliders alone.
TintMultiplies the image's colour and transparency: fade a sprite out, or colour it.
Draw ModeHow the image fills Width and Height (below).
Draw ModeWhat it doesIts setting
StretchThe image is scaled to fit.
9-SliceCorners keep their size while edges and centre stretch, for panels, frames and platforms that resize cleanly.Slice Border: how far in from each edge, in image pixels.
TileThe image repeats to fill, for floors, walls and backgrounds.Tile Scale: 1 repeats at the image's own size, 2 at double.

Sprite sheets. Click Add Sheet, then set H Frames and V Frames to slice the image into columns and rows. Frame picks which cell shows. To play frames as an animation, see Sprite Animation.

Sprite materials. A sprite can wear a material for effects like a dissolve, a flash or a palette swap. Make one with Sprite Material in the Assets panel's new-file menu and drag it onto the sprite. See Materials.

Draw order

What draws in front of what follows the Hierarchy, the way layers work in an image editor:

  • Higher in the Hierarchy draws in front. Drag an entity up to bring it forward.
  • Children draw together, over their parent. An empty entity works as a group: put the sky and far hills in a "Background" group, the props and player in an "Objects" group.
  • A tilemap is a group too. Its paint layers are its children, so you can drag a sprite in between two of them: a roof that draws over the player while the floor stays under.
  • New entities arrive at the top, in front of everything.

The Z position does nothing to draw order in 2D.

Y Sort

In a top-down game a character should walk behind a tree when above it and in front of it when below. Switch on Y Sort on the Sprite Image card and, among siblings, things lower on screen draw in front, updated every frame.

Sort Offset moves the sort point away from the sprite's centre. For a tall tree, put it at the base of the trunk (roughly minus half the sprite's height), and do the same for your character's feet.

While a y-sorted sprite is selected, a cyan line with a diamond marks its sort height. Two sprites swap order exactly when their cyan lines cross, so you can tune the offset by eye.

Y Sort only sorts siblings against each other. Put the player and the trees in the same group (or both at the top level) for them to sort together.

Text

Add Entity > Text 2D places text in the world: a sign, a label over a chest, a damage number. Set its font, size and colour on its card. The size is in world units, so 16 is one default tile tall.

Colliders

Give a sprite a Collision Shape (see Physics). To fit it to the art, press Edit on the Collision Shape card: a green frame with handles appears over the collider. Drag a handle to resize it, or drag inside to move it, for example to trim a tree's collider down to its trunk. Each drag is one undo step.

For outlines a box can't follow (a slope, an L-shaped ledge, a rock), pick Polygon as the shape:

ActionWhat it does
Drag a pointMoves it
Click an edgeAdds a point there
Alt and click a pointRemoves it (down to three)
Drag insideMoves the whole outline

Switch on One-Way (2D) for a platform you can jump up through and land on.

A camera that follows the player

Add Camera Follow 2D to your Camera 2D and pick the Target from the list of named entities. While the game runs, the camera keeps it in view.

FieldWhat it does
TargetThe entity to follow.
Follow SpeedHow quickly the camera catches up. Higher is snappier; 0 sticks to the target exactly. Default 8.
Pixel SnapDraws the camera at whole pixels so pixel art never shimmers, while the follow itself stays smooth.
Dead ZoneA box round the centre of the view the target can move in before the camera follows.
OffsetShifts the view from the target, such as more room above a platformer's hero.
LimitsKeeps the view inside a box, so it never shows past the edge of the level.

Fit to Game Area puts the limits back on the game area. With the camera selected, the limits show as a blue rectangle in the view: drag an edge to move it, holding Shift to land it on the grid.

The camera only moves while the game runs, so editing never changes where it is saved. On the first frame it starts on the target instead of sweeping in.

Parallax backgrounds

Add Parallax 2D to a background sprite and it scrolls at its own rate behind the camera, which reads as depth.

FieldWhat it does
Scroll ScaleHow much of the camera's movement the layer follows. 1 moves with the world, 0 stays fixed on screen (a sky), 0.5 (the default) drifts at half speed. Above 1 is a foreground layer passing faster than the world.
Auto ScrollA steady drift of its own, in world units per second, for clouds or stars.
Repeat X / Repeat YTile the sprite endlessly along that axis, so the background never runs out.
Step X / Step YThe distance between copies. 0 uses the sprite's own size, right for a seamless image; bigger leaves gaps, for scattered hills or clouds.

Stack several layers, the furthest with the smallest scale. In the editor nothing moves, but repeated copies are drawn so you can judge a tiled backdrop.

Playing a 2D scene

Press Play and the game draws through the Camera 2D. What sits inside the amber game area in the editor is what shows on screen. See Play Mode.

Next