Skip to content

Tutorials · Worlds and Levels · Chapter 7

Made to measure

75 minutes Uses: Mesh, Polygon, Shape

By the end

  • A sky, sky, in place of sky-block: a Mesh of six vertices typed in linear light, night to dusk to dawn, carried by a Parallax so it holds still on the screen, the sun under it
  • One region cut from Gothic Horror’s clouds and two from its town, and two Parallax planes drifting behind the vale, the clouds on their own as well
  • Four banners, banner-1 to banner-4, in place of banner-block: a Polygon pennant made a Mesh with Make a Mesh, its Uvs typed onto its own quarter of one sheet
  • A rope between two poles, three Shapes, for the banners to hang from
On this page

When to reach for a Mesh

Two of the vale’s grey stand-ins are this chapter’s: sky-block, a grey wall behind everything, and banner-block, a grey box over the market. It replaces the first with a sky and the second with four banners.

Reach for a Mesh for a shape you colour and map yourself, point by point: a colour at each corner, blended across the shape, or a part of a picture pinned to each point. A Mesh is points and the triangles between them, typed in the Inspector, and has no handles to drag. The Polygon of chapter 6 stays the tool for an outline drawn by hand: draw one, then make it a Mesh, as the banners are made.

What collides, what draws, what sorts: a Mesh draws its triangles, coloured by its points and its Texture, and collides with nothing. It sorts as one node on its Sort Layer, and there it draws before a picture it ties with.

The sky

The sky is a Mesh of two bands, each a rectangle of two triangles: night along the top fading to dusk across the middle, and dusk fading to dawn along the foot. Each colour is a vertex’s, blended across the triangles between them. A Parallax at Factor 1 carries it with the camera, so its numbers are places on the screen from the view’s middle, and it never runs out.

  1. With scenes/vale.ron open, select sky-block, press Delete, and press Delete in the box that asks; do the same for banner-block.
  2. Select vale, press + Add node and choose Mesh: the menu lists it after MultiMesh. Rename it sky and leave its Position at 0, 0. It comes white, a 64-unit square of four Vertices and the Indices 0 1 2 0 2 3.
  3. Press Add component and choose ParallaxComponent. Type its Factor 1, 1, and leave the rest as it comes.
  4. In the Mesh, press + beside Vertices twice, for six. Open each of [0] to [5] and type its Position and Color from the table below; leave each Uv as it is.
  5. Press + beside Indices six times, for twelve, and type the six new ones 1 4 5 1 5 2. Tick Opaque. Leave Texture at none, Color white and Sort Layer on Sky.
VerticesPositionColor
[0]-176, -1060.0100, 0.0134, 0.0732, 1night, top left
[1]-176, 00.2633, 0.1329, 0.2633, 1dusk, middle left
[2]176, 00.2633, 0.1329, 0.2633, 1dusk, middle right
[3]176, -1060.0100, 0.0134, 0.0732, 1night, top right
[4]-176, 1061.0, 0.4770, 0.2633, 1dawn, bottom left
[5]176, 1061.0, 0.4770, 0.2633, 1dawn, bottom right

The colours are typed in linear light, as chapter 6’s mere is: night shows on the screen as 0.10, 0.12, 0.30, dusk as 0.55, 0.40, 0.55 and dawn as 1.0, 0.72, 0.55. The Indices 0 1 2 0 2 3 are the top band and 1 4 5 1 5 2 the bottom one: 352 by 212 about the view’s middle, 16 past each of its edges, the bands meeting at its middle row. Blue holds at 0.2633 down the bottom band, so each colour runs one way from the top to the foot, and never back.

The Inspector on sky from its MeshComponent down: Vertices, 6 items, with [0] open, Position -176.0 and -106.0, Uv 0.0 and 0.0, and a dark blue Color, then [1] to [3] closed, [4] open, Position -176.0 and 106.0, Uv 0.0 and 0.0, and a peach Color, and [5] closed; Indices, 12 items, 0 1 2 0 2 3 1 4 5 1 5 2, each with up, down and bin buttons; Texture (none), a white Color, Sort Layer Sky and 0, Opaque ticked; then the ParallaxComponent: Factor 1.0 and 1.0, Offset 0.0 and 0.0 u, Autoscroll 0.0 and 0.0 u/s, a white Color, Repeat X ticked, Repeat Y unticked, Repeat Period 0.0 and 0.0 u
The sky’s Mesh with [0] and [4] open, and the Parallax that carries it.
Vertices
The Mesh’s points, each opened by its arrow to show its rows; + adds one at the end, and the bin takes one off. They have no handles in the Viewport: they are typed here, or made from a Polygon with Make a Mesh.
The vertex’s Position, Uv and Color
Position is the point’s place in the node. Uv is which point of the Texture is drawn at it, 0, 0 the picture’s top-left corner and 1, 1 its bottom-right; with no Texture nothing reads it. Color is the point’s own colour, typed in linear light, blended across every triangle the point is a corner of.
Indices
Which points make each triangle, three at a time, counted from 0 in the order of Vertices. While a count is not a multiple of three, Problems says so: “This Mesh has 7 Indices, which is not a multiple of three, so the last 1 make no triangle and are not drawn — each triangle is three Indices”. An Index past the last point is named too, and its triangle not drawn.
The Mesh’s Texture
The picture the triangles are drawn with, each point showing the part its Uv names; none draws flat colour, the points’ own.
The Mesh’s Color
A tint multiplied with every point’s own colour. White as the preset comes, so the sky’s points show as they are typed.
The Mesh’s Sort Layer
The sorting layer the Mesh draws on: the sky on Sky, behind everything.
The Mesh’s Opaque
Draws the triangles without blending, for a backmost shape nothing shows through. The sky is ticked: nothing is behind it.
The Parallax’s Factor
How much of the camera’s motion the node is carried along by, across and up and down. At 1 it moves as the camera does, so it holds still on the screen; at 0.5, half as far, so it drifts behind.
The Parallax’s Repeat X
Copies the pictures and tilemaps under the node side by side so the layer never runs out, ticked as it comes. It copies no mesh: the sky is drawn once, and needs no copy, since it moves with the camera.

The sun under the sky

  1. In the Hierarchy, drag sun onto sky: it becomes the sky’s child, carried with it. Type its Position -80, -45, a place on the screen.

The sun keeps its Shape, a Circle 40 across with its ring, and its Sort Layer, Far, in front of the sky on Sky. Its disc lies inside the view’s top-left quarter wherever he walks.

sky selected and framed at 203.2%: its outline, 352 by 212, in the middle of the Viewport, filled with the sky’s dusk and a strip of peach dawn along its foot at the left; over it the sun, the clouds, the town’s skyline and the hut, drawn where the editor’s view carries them; the status line says at 0.0, 0.0 size 352.0, 212.0; in the Hierarchy the sun is under sky; the Inspector shows Name sky, Position 0.0 and 0.0, and its MeshComponent with Vertices, 6 items, and Indices, 12 items
The sky in the editor at the chapter’s end: its 352 by 212, carried to the middle of the view.

Clouds and a town

Behind the vale, two pictures from Gothic Horror drift: its clouds and its town at night. Each is cut into regions first, in the Sprite sheet tab, as chapter 6 cut the tower, so that a plane shows only the rows it needs.

  1. Copy both pictures above into art, and press Refresh in Assets.
  2. Double-click art/gothic-horror-clouds.png in Assets: the Sprite sheet tab opens on it. If its top and foot are cut off, pick 200% from the zoom menu at the tab’s foot to see it whole.
The Sprite sheet tab on gothic-horror-clouds.png, 256x176, its zoom set to 200% from the menu at its foot: Grid with Cell w 32 h 32, Margin and Spacing 0, 8 x 5 cells; Regions saying Select cells to name a region.; and the picture whole under a grid of 32-pixel cells, rows of olive and pale yellow clouds over its upper part, and a flat band of olive along its foot
The clouds at 200%, before the cut: the clouds above, a flat band below.
  1. Type Cell 256 and 108, and Margin 0 and 0: one cell, the picture’s rows 0 to 107. Click it, type band beside Name it, and press Name it.
  2. Double-click art/gothic-horror-town.png: the tab opens on it. Again, if its top and foot are cut off, pick 200% from the zoom menu at the tab’s foot.
The Sprite sheet tab on gothic-horror-town.png, 256x176, its zoom set to 200%: Grid with Cell w 32 h 32, 8 x 5 cells; Regions saying Select cells to name a region.; and the picture whole under a grid of 32-pixel cells, its top rows empty, then a dark green skyline of houses with lit windows, trees and a tall spire, over a band of ground with bushes
The town at 200%, before the cuts: empty rows, the skyline, the ground.
  1. Type Cell 256 and 96, and Margin 0 and 16: the houses, rows 16 to 111. Click the cell, type skyline and press Name it.
  2. Type Cell 256 and 64, and Margin 0 and 112: the ground, rows 112 to 175. Click the cell, type ground and press Name it.

Why cut them: the clouds’ rows 108 to 175 are one flat colour, which laid over the sky would wash the dawn olive; the town’s rows 0 to 15 are empty; and its ground, rows 112 to 175, is opaque, so it can be drawn on its own, without blending.

  1. Select vale, press + Add node and choose Parallax: a Parallax with a Sprite beside it. Rename it clouds and type its Position 0, -42. In the Parallax, type Factor 0.9, 1 and Autoscroll -4, 0; leave Repeat X ticked.
  2. In its Sprite, drag art/gothic-horror-clouds.png onto Texture, type band in Atlas Region and Size 256, 108, and set Color to 1.0, 0.86, 0.78, alpha 0.5. Leave its Sort Layer on Sky.
  3. Select vale again, and add a second Parallax: town, at Position 0, -16, Factor 0.5, 1. In its Sprite, drag art/gothic-horror-town.png onto Texture, type skyline in Atlas Region and Size 256, 96, and set Sort Layer to Far.
  4. Right-click town in the Hierarchy and choose Duplicate: town copy appears straight after it. Rename it town-ground, type its Position 0, 64, and in its Sprite type ground in Atlas Region and Size 256, 64, and tick Opaque.

At a Factor of 1 up and down, a Position is a place on the screen up and down from the view’s middle. The clouds’ band, at -42, covers the view’s top edge, its lower edge behind the skyline; the skyline stands at -16; and town-ground, at 64, covers the view’s foot under the bridge. town-ground is the town’s duplicate, so the two tile alike. The clouds are faded by their Sprite’s Color; the Parallax’s own Color stays white.

The Parallax’s Autoscroll
World units a second the node drifts on its own, on top of what Factor carries it: the clouds’ -4, 0 drifts them west.
Pictures tied on one Sort Layer
Front and back are the Sort Layer first, whatever the Hierarchy’s order. Two pictures tied on one Sort Layer draw in the order of their textures, not the scene’s: on Far, the clouds would draw over the town whichever came first in the Hierarchy. So the clouds stay on Sky, as their Sprite comes, where they draw over the sky, since a mesh draws before a picture it ties with, and under the sun and the town on Far. To put one picture in front of another, give it a later Sort Layer.

The cost: a plane that blends is paid for at every pixel it covers, and on a phone that is the cost that bites. With the clouds cut to their band and the town’s ground drawn Opaque, only the band and the skyline blend: 1.10 views of blending, where the whole pictures were 1.89.

The banners

Four banners hang over the market, each a swallowtail pennant 16 wide and 48 long, all four showing their own quarter of one sheet, art/banners.png, 64 by 48, which came with the starter. Each is drawn as a Polygon, by hand, and then made a Mesh, so its points can be pinned to its quarter of the sheet.

  1. Select vale and add a Polygon. Rename it banner-1 and type its Position 2432, -104. 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, top left, bottom left, bottom right, top right, onto [0], [1], [3] and [4] of the table below. Double-click the bottom edge halfway along: a point goes in there, between the two bottom corners. Drag it up to 0, 36, the notch.
  3. In the Inspector, type each point from the table, so all five are exact.
Pointsx, y
[0]-8, 0
[1]-8, 48
[2]0, 36
[3]8, 48
[4]8, 0
The Inspector on the mere, a Polygon, from its PolygonComponent down: Points, 6 items, a light blue Color, Texture mere.png, Fit Tile, Tile Scale 2.00, Sort Layer Water and 3, Opaque unticked, then the Make a Mesh button and Add component
Make a Mesh, under a Polygon’s rows: here the mere’s.
  1. Under the Polygon’s rows, press Make a Mesh. The Polygon is replaced by a Mesh of its five points and three triangles, the Indices 4 0 1 4 1 2 2 3 4.
  2. In the Mesh, drag art/banners.png onto Texture, and set Sort Layer to Props.
  3. Open each of the five Vertices and type its Uv from banner-1’s row of the table below.
  4. Do the same for banner-2, banner-3 and banner-4, selecting vale before each add: banner-2 at Position 2464, -104, banner-3 at Position 2496, -104 and banner-4 at Position 2528, -104, each typing its own row. Set banner-4’s Mesh Color to 0.9, 0.9, 1.0, alpha 1; leave the rest white.
Uv[0][1][2][3][4]
banner-10, 00, 10.125, 0.750.25, 10.25, 0
banner-20.25, 00.25, 10.375, 0.750.5, 10.5, 0
banner-30.5, 00.5, 10.625, 0.750.75, 10.75, 0
banner-40.75, 00.75, 10.875, 0.751, 11, 0

Each banner’s Uvs are a quarter of the sheet across, from its left edge to its right, and the whole of it down: banner k shows the sheet’s x 16(k − 1) to 16k, a pixel of the sheet to a unit of the world. The notch’s Uv is 0.75 down, as its point is 36 of the 48.

The Inspector on banner-1 from its MeshComponent down: Vertices, 5 items, [0] to [4] closed; Indices, 9 items, 4 0 1 4 1 2 2 3 4; Texture banners.png; a white Color; Sort Layer Props and 5; Opaque unticked
What it makes: banner-1’s Mesh at the chapter’s end.
Make a Mesh
Under a Polygon’s rows: replaces the Polygon with a Mesh of the triangles it is drawn with, each point’s Uv where it stands in the outline’s box and every point white. Its Color, Texture, Sort Layer and Opaque come across, so the Mesh looks as the Polygon did. A Mesh has no Fit, so a Polygon set to Tile comes out stretched, and the button’s hover says so. One undo puts the Polygon back. It is greyed on a node that already has a Mesh, and on an outline of fewer than three points.

A rope between two poles

  1. Add a Shape three times, for the table below, selecting vale before each add, so all three are its children: rename each, type its Position, and in its Shape type its Size and Anchor.
  2. Give each Color 0.147, 0.064, 0.022, alpha 1 and Outline Color 0.033, 0.013, 0.005, alpha 1, a dark wood, which chapter 10 gives the signposts too, Outline 1, and set Sort Layer to Props. Press Ctrl+S.
NodePositionAnchorSize
banner-pole-west2384, 00.5, 14, 112
banner-pole-east2600, 00.5, 14, 112
banner-rope2492, -1080.5, 0220, 4

The poles stand in the market’s gaps, clear of the carts and the stalls, and the rope runs between their tops, x 2382 to 2602, the banners hanging from its foot at y -104.

In the game

Press Run game and hold D. The sky and the sun hold still on the screen; the town and the clouds drift behind.

The game: from the hut he walks east, the view following him; the sky and the sun stay where they are on the screen, the town’s houses and spire slide back behind him, and the clouds slide back slowly
Two seconds east. Watch the sky and the sun hold still on the screen, while the town slides back behind him and the clouds slide back more slowly.

Held two seconds, the camera moves 268.5 units east and the sky with it, not a pixel on the screen, the sun in the view’s top-left quarter before and after. In one second the town moves on half as far as the camera, so on the screen it falls back by half the camera’s motion; the clouds move on nine tenths as far, and 4 a second west of their own, so they fall back by a tenth and their drift.

A copy of the game with every node but the sky hidden: the whole window a smooth fade, dark violet at the top, violet across the middle and warm peach at the foot
A copy with all but the sky hidden: night, dusk, dawn.

With all but the sky hidden, down the middle of the window each colour never turns back: between night and dusk at the top, nearer night; dusk on the middle row, where the bands meet; and between dusk and dawn at the foot, nearer dawn. In the game the clouds cover the view’s top edge, and the ground its foot.

A part of the game at the market: him standing under a rope stretched between two thin wooden poles, four pennants hanging from it, red with a castle, dark green with a moon, olive with a sun, purple with a fish, each its own; behind them the sun, the clouds and the town, and the grey stand-ins of the carts and a stall
At the market: each banner shows its own quarter of the sheet.

Each banner is drawn from the sheet once, at its node, with its own Uvs: four draws of one picture, and four different pennants. The clouds and the town show only the regions cut for them, each copy at its region’s size; every copy of the clouds draws before the town’s, and town-ground draws Opaque under the skyline, which blends.

The sky, the planes and the banners

NodePositionFactorAutoscrollPictureSort Layer
sky0, 01, 10, 0a Mesh, the table above, OpaqueSky
clouds0, -420.9, 1-4, 0band, 256 by 108, Color 1.0, 0.86, 0.78, 0.5Sky
town0, -160.5, 10, 0skyline, 256 by 96Far
town-ground0, 640.5, 10, 0ground, 256 by 64, OpaqueFar
RegionPictureCellMargin
bandgothic-horror-clouds.png256, 1080, 0
skylinegothic-horror-town.png256, 960, 16
groundgothic-horror-town.png256, 640, 112

The sun, under sky, at -80, -45. The banners at x 2432, 2464, 2496 and 2528, y -104, each the pennant’s five points and its own row of Uvs, banners.png, Props, banner-4 tinted 0.9, 0.9, 1.0. sky-block and banner-block are gone.

Check it works