Skip to content

Tutorials · Worlds and Levels · Chapter 6

Water and stone

45 minutes Uses: Polygon

By the end

  • A region, tumbled, cut from Gothic Horror’s sheet in the Sprite sheet tab: the fallen tower alone
  • The cliff, cliff, in place of cliff-block: a Polygon traced from the tower with Generate physics shape, 14 points, earth tiled over it, Opaque on Back
  • The mere, mere, in place of mere-block: the Polygon preset’s square drawn into six points, its water tiled at twice its size and see-through on Water
  • A colour chosen by its screen numbers, typed in linear light
On this page

When to reach for a Polygon

Behind the mere the vale still has two grey stand-ins: cliff-block, a box, and mere-block, a strip on the walking line. This chapter replaces both with Polygons: a fallen tower for the cliff, and still water for the mere.

Reach for a Polygon for a flat outline you fill: a pool, a slope seen from the side, a backdrop’s shape. It is one list of points, filled with a picture or a colour, and has no edge art of its own. Chapter 2’s tiles stay the tool for anything on a grid, chapter 5’s Sprite Shape for ground with edges along it, and chapter 7’s Mesh for a shape you colour and map point by point.

What collides, what draws, what sorts: a Polygon draws its outline filled, and collides with nothing; what collides is a Collider, and neither the cliff nor the mere has one, so he walks in front of both. It sorts as one node on its Sort Layer: the cliff on Back, the mere on Water in front of it, and the hills’ turf, on Ground, over the mere’s near shore.

The fallen tower

The cliff is a fallen tower, drawn at the right-hand end of Gothic Horror’s sheet among its tiles. First the tower is cut out of the sheet as a region of its own: a rectangle of the picture with a name, which a Sprite can show in place of the whole sheet.

  1. Copy the picture above into art, and press Refresh in Assets.
  2. Double-click art/gothic-horror-tiles.png in Assets. The Sprite sheet tab opens on it.
The Sprite sheet tab on gothic-horror-tiles.png, 1056x176: Grid with Cell w 32 h 32, Margin and Spacing 0, Detect grid and 33 x 5 cells; Clips with Skip blank cells and One per row, Nothing to generate yet; Regions saying Select cells to name a region.; Paint; and the sheet drawn small under a grid of 32-pixel cells, bricks, ledges, arches and a lit doorway at its left, a brick house front grown over with ivy in the middle and, at its right end, the fallen tower lying on its side; at the foot Cell - and 71.1%
Gothic Horror’s sheet as the tab opens on it: the fallen tower at its right-hand end.
  1. In the Grid band, type Cell 254 and 154, and Margin 784 and 22. The line under them reads 1 x 1 cell: the grid’s one cell is the tower alone.
  2. Click the cell, the tower, in the picture. Under Regions, type tumbled in the box beside Name it, and press Name it. tumbled is listed under it.
The Sprite sheet tab’s Cell and Margin
How the tab cuts the picture into a grid: Cell is one cell’s width and height, in the picture’s pixels; Margin is the blank border before the first cell, across and down. The tower is 254 wide and 154 tall, starting 784 pixels across and 22 down, so it is x 784 to 1038 and y 22 to 176 of the sheet. These numbers are only the tab’s way of cutting: what is kept is the region named from them.
Name it
Names the cells selected, as one rectangle, a region of the picture, and writes it into the picture’s settings beside it, where every Sprite that shows the picture can name it in its Atlas Region. Its hover says the rectangle: 254x154 at 784, 22. A name already on the sheet is refused, and the bin beside a region takes it off.

The cliff, traced

A Polygon could be drawn round the tower point by point. Instead the tower is shown on a Sprite, and the Sprite’s picture is traced: the editor follows the edge of its opaque pixels and writes the outline into a Polygon.

  1. With scenes/vale.ron open, select cliff-block, press Delete, and press Delete in the box that asks; do the same for mere-block.
  2. Select vale, press + Add node and choose Sprite. Rename it cliff, and type its Position 1200, 48: 48 under where the grey cliff stood, so the tower’s top is in view while he walks and its foot is behind the hills.
  3. In its Sprite, drag art/gothic-horror-tiles.png onto Texture and type tumbled in Atlas Region. Type Size 254, 154, the region’s, and Anchor 0.5, 1, so it stands on its foot.
  4. In the Sprite’s Physics shape fold, leave Alpha above at 8, Tolerance at 2 px and Min area at 16, and press Generate physics shape. The line under it says it wrote 14 vertices, and a PolygonComponent appears under the Sprite.
  5. Press the bin on the SpriteComponent’s head, and Remove in the box that asks. The Polygon stays, white.
  6. In the Polygon, drag art/earth.png onto Texture and set Fit to Tile; leave Tile Scale at 1. Set Color to 0.16, 0.15, 0.20, alpha 1, which darkens the earth to a dark brown, set Sort Layer to Back, and tick Opaque.
cliff selected and framed at 279.8%: a dark slab of tiled earth, the fallen tower’s outline, leaning to the right, a square handle on each of its points, most along its broken top; the blue mere lies in front of its foot and the hills’ turf crosses below; the Inspector shows Name cliff, Position 1200.0 and 48.0, and its PolygonComponent with Points, 14 items, from -127.0 and -1.0
The cliff at the chapter’s end: the tower’s outline, traced, 14 points.
The Inspector on cliff: Name cliff, Position 1200.0 and 48.0; its PolygonComponent with Points, 14 items, [0] -127.0 and -1.0 to [13] -66.0 and -154.0; a grey-violet Color; Texture earth.png; Fit Tile; Tile Scale 1.00; Sort Layer Back and 2; Opaque ticked
The cliff’s Polygon: the traced points, the earth tiled, Back, Opaque.
Generate physics shape
Under a Sprite’s Physics shape fold: traces the edge of the picture the Sprite shows, at its Size and from its Anchor, and writes the outline into the node’s Polygon, adding one if it has none. With an Atlas Region it traces that region alone, not the whole sheet: the whole sheet traces to another outline, of 49 points. Alpha above is how opaque a pixel must be to count, 8 as it comes; Tolerance how far, in pixels, the outline may stray from the traced edge to save points, 2 px; Min area the smallest island worth an outline, 16 square pixels. The line under the button says how many points it wrote. One undo takes it back.
The Polygon’s Points
The outline, in order, each point a place in the node. The last joins the first: a Polygon is always closed. Its points are dragged in the Viewport, or typed in this list, [0] onwards.
The Polygon’s Texture
The picture the outline is filled with, laid as Fit says; none fills with flat Color.
The Polygon’s Fit: Stretch and Tile
Stretch, as it comes, spreads the picture once across the outline’s whole extent. Tile repeats it at its own size times Tile Scale, counted from the node’s origin.
The Polygon’s Tile Scale
World units each pixel of the picture covers under Tile: 1 draws it at its own size, the earth’s 32 pixels a repeat of 32 units; 2 at twice that.
The Polygon’s Color
A tint over the fill, alpha included: alpha under 1 lets what is behind show through. White as it comes. A colour is light, typed in linear light: see below.
The Polygon’s Sort Layer
The sorting layer the Polygon draws on. The cliff is on Back, behind the mere on Water and the hills on Ground.
The Polygon’s Opaque
Draws the fill without blending, for a backmost shape nothing shows through: its see-through parts, and a see-through Color, come out dark instead of showing what is behind. The cliff is ticked: only the sky is behind it.

The mere, drawn

The mere is drawn by hand, from the Polygon preset’s square. Its points are a shallow bowl: its far shore at y -28 under the cliff, its near shore on the walking line. art/mere.png, a tile of still water, came with the starter.

  1. Select vale, press + Add node and choose Polygon: the menu lists it after Sprite Shape. Rename it mere, and type its Position 1200, 0. Click the Viewport tab, since the Sprite sheet tab is still in front of it, and press Frame: the square is in the middle of the view.
  2. With Snap off, drag the square’s four corners, in the order the list holds them, top left, bottom left, bottom right, top right, onto [0] to [3] of the table below.
  3. Double-click the top edge, the one from [3] back to [0], halfway along: a point is inserted after [3]. Drag it near [4]. Double-click the edge from [4] back to [0] and drag the new point near [5].
  4. In the Inspector, type each point’s x and y from the table, so every point is exactly where the table puts it.
PointsxyIn the world
[0]-112-181088, −18
[1]-16001040, 0
[2]16001360, 0
[3]112-181312, −18
[4]48-281248, −28
[5]-48-281152, −28
  1. Drag art/mere.png onto Texture, set Fit to Tile and Tile Scale to 2.
  2. Set Color to 0.263, 0.571, 0.831, alpha 0.7, from the table in the next section, and Sort Layer to Water. Leave Opaque unticked. Press Ctrl+S.
mere selected and framed at 256.5%: a shallow bowl of light blue rippled water, a square handle on each of its six points, its far shore under the dark cliff and its near shore on the walking line, where the hills’ turf crosses it; the Inspector shows Position 1200.0 and 0.0, Points, 6 items, -112.0 and -18.0, -160.0 and 0.0, 160.0 and 0.0, 112.0 and -18.0, 48.0 and -28.0, -48.0 and -28.0, a light blue Color over a chequer, Texture mere.png, Fit Tile, Tile Scale 2.00 and Sort Layer Water and 3
The mere at the chapter’s end: six points, its water tiled at Tile Scale 2.

A Polygon’s points are edited as chapter 5’s Sprite Shape’s are: drag a point; double-click an edge to insert one; hover a point and press Delete to take it off. A Polygon keeps three, the fewest that enclose anything: at three, the status line says “This outline keeps at least 3 points — move off its points to delete the node”.

The first three points
A Polygon with fewer than three points draws nothing, and Problems says so: “This Polygon has 2 points, and it takes three to enclose anything, so it draws nothing — click in the Viewport to place its points, or add them under Points”. While one is selected, a plain click in the Viewport puts its next point where the click lands, rather than picking a node in front of it, each click one step to undo. To stop drawing, select another node in the Hierarchy.

Colours in linear light

The mere’s water is meant to show on the screen as 0.55, 0.78, 0.92, a pale blue. Typed as those numbers, it draws paler still. Its Color is typed as the numbers below instead.

ColorOn the screen
The mere0.263, 0.571, 0.831, alpha 0.70.55, 0.78, 0.92
Typed in linear light
A Color is light, not a screen number. The game adds light up in linear light and writes the frame as screen numbers, which brightens all but the ends: a light of 0.263 shows as 0.55, so a colour typed as its screen numbers draws paler than chosen. A colour chosen by its screen numbers is typed as the light that shows as them. In the picker’s F mode, as this tutorial gives every colour, the numbers are the light; its U8 mode shows the screen’s, out of 255. The sky, the meadow and the signposts in the chapters ahead are given the same way, each with the screen numbers it shows as. Alpha is not light, and is typed as it is.

In the game

Press Run game and hold D until he stands by the mere, at x 1200. The tower stands behind the water on Back, its foot behind the hills, its top in view.

A part of the game: him standing on the turf by the mere; behind him the fallen tower, a dark slab of tiled earth leaning right, against the grey sky; in front of its foot the light blue water, its ripples in rows, darker where the tower stands behind it
By the mere: the tower shows through the water.

The water repeats every 64 units, one 32-pixel picture at Tile Scale 2, 256 pixels on the screen, and not every 32. It lets through 0.3 of the tower behind it, one less its alpha of 0.7: measured, 0.302. The cliff draws without blending, where the hills’ earth in the same frame blends. Its outline is the trace of tumbled alone, 14 points within its 254 by 154.

Why Tile: a copy with both Polygons back on Stretch, as the preset comes, spreads each picture once across its outline.

The same part of the game on a copy with both Fits at Stretch: the tower’s earth blown up into big square blocks of brown and black, and the mere’s water stretched into long smooth bands of blue
A copy with Fit at Stretch: one picture spread over each outline.

And why the mere’s Opaque stays unticked: a copy with it ticked draws the water without blending.

The same part of the game on a copy with the mere’s Opaque ticked: the water one even blue with its rows of ripples, the same in front of the tower as at its two ends, where the grey sky is behind it; the tower’s foot no longer shows through, and the ends are darker than the see-through water’s
A copy with the mere’s Opaque ticked: the tower no longer shows through.

Its see-through Color comes out darker instead of showing what is behind: one blue in front of the tower and the sky alike. The cliff takes Opaque because nothing but the sky is behind it.

The two Polygons

Fieldcliffmere
Node Position1200, 481200, 0
Points14, traced from tumbled at 254 by 154, Anchor 0.5, 1six, the table above
Texture, Fit, Tile Scaleearth.png, Tile, 1mere.png, Tile, 2
Color0.16, 0.15, 0.20, 10.263, 0.571, 0.831, 0.7
Sort LayerBackWater
Opaquetickedunticked

The region tumbled on gothic-horror-tiles.png: Cell 254 by 154 at Margin 784, 22. cliff-block and mere-block are gone.

Check it works