Skip to content

Tutorials · Worlds and Levels · Chapter 10

Words in the world

60 minutes Uses: WorldText, Shape, in_group, set_text, anneal_point, vec2, anneal_colour, vec4

By the end

  • The signposts’ face, Kenney High, read at 32 px with a distance field, set in the Import panel
  • The four boards and their posts in wood, on Ground, sign-hut and sign-mere widened to their words
  • Each board’s words, a World Text drawn from the face’s distance field with an outline and a soft shadow, lined up Left, Center or Right
  • A name tag on each pilgrim, tag, kept at its size on the screen, and Unshaded in the crypt
  • A “+1” over the mere’s sign, plus-one, which waymark.rgs sets off once: it rises and fades
On this page

When to reach for World Text

The four signposts from chapter 1, sign-hut, sign-mere, sign-market and sign-chapel, are still grey boards on grey posts with nothing written on them. This chapter turns them wood and gives each its words.

Reach for a World Text for words that stand in the room: a sign, a name tag, a number that floats up. Its words stand at a point, the node’s own place and an Offset, move with the node, and are drawn by the room’s camera. Words that belong to the screen, a score or a menu, are a Canvas’s Label instead, which the camera never moves.

What collides, what draws, what sorts: a World Text draws its words and collides with nothing. It sorts on its own Sort Layer, as a picture does: the boards on Ground, their words on Props, him on Figures, his tag on Words. A World Text whose face cannot give it what it asks for is a Problems row: see the face, below.

A face for the signs

The signs’ words are carved in Kenney High, from Kenney Fonts. A font is read at a size in pixels, and can bake a second copy of itself, a distance field, from which words are drawn sharp at any zoom, their outline and shadow in the same pass.

  1. In your file manager, open the worlds-and-levels folder and make a folder in it called fonts, beside art. Copy the font above into it under the name the list gives, kenney-high.ttf: no space and no capital. Back in the editor, press Refresh in the bar of Assets.
  2. In Assets, open fonts, click kenney-high.ttf, and press Details in the panel’s bar. The Import panel opens under the list, headed Details: the font’s two rows, Size and Distance field, each with As the project’s ticked.
  3. In the Size row, untick As the project’s: the size shows the project’s, 16 px. Type 32.
  4. In the Distance field row, untick As the project’s and tick On. Press Save.
The Assets panel with Details lit, its path bar at Assets / fonts over the folders art, artifacts, fonts and scenes and chapel_door.rgs; under them the Details fold on kenney-high.ttf: Font, hand-edited, its path fonts/kenney-high.ttf and its id; Preset (custom); Size, As the project’s unticked, 32 px; Distance field, As the project’s unticked, On ticked; Save, Revert to default, Default for .ttf and Reimport; Import rules (0), folded
The font’s rows in the Import panel, saved: 32 px, with a distance field. The list above shows fonts closed.
The Import panel’s Size
The pixel size the font is read at. A World Text in it draws at this size times its Scale: at 32 and Scale 0.5, the signs’ face draws at 16 units: a line of it is 12 high, its letters 9. As the project’s, ticked as it comes, takes the size of the project’s own face, 16, shown greyed beside it.
The Import panel’s Distance field
Whether the font also bakes a distance field. With it, a World Text in this face set to DistanceField draws sharp at any zoom and can soften its shadow. As the project’s, ticked as it comes, takes the project’s face’s setting, which is off.
The Import panel’s Save
Writes the rows into the font’s settings, kenney-high.ttf.meta beside it, which every World Text in this face then reads, in the editor and in the game.

Leave Distance field to the project’s, and each sign’s words below would be a Problems row, asking for a field this face has not baked: “This World Text asks for Distance Field and its font fonts/kenney-high.ttf has no distance field, so its outline and shadow are drawn as copies and its Shadow Softness is not read — tick Distance field in the font’s import settings”.

Wood

Each signpost is two Shapes: a board, and under it its post. Both turn wood, a brown chosen by its screen numbers and typed in linear light, as chapter 6’s mere is.

  1. Select sign-hut and press Frame. In its Shape, with the picker reading F, set Color and Outline Color from the table below, leave Outline at 1, and set Sort Layer to Ground.
  2. Do the same for sign-hut-post, and for each of the other three boards and its post: sign-mere, sign-market and sign-chapel.
  3. Type sign-hut’s Size 68, 16, and sign-mere’s Size 50, 16. Press Ctrl+S.
WoodTypedOn the screen
Color0.147, 0.064, 0.022, alpha 10.42, 0.28, 0.16
Outline Color0.033, 0.013, 0.005, alpha 10.20, 0.12, 0.06
The Shape’s Color and Outline Color
The board’s fill and the line round its edge. A post takes the same two, so the post and its board are one piece of wood.
The Shape’s Sort Layer
Where the board draws: on Ground, under its words on Props. A board and its words tied on one Sort Layer would draw in the order of their textures, not the scene’s, as chapter 7’s pictures tied on one layer do, and the words could be drawn under their own board.
The Shape’s Size
Its width and height. In the signs’ face at Scale 0.5, “Hollowmere” is 64 wide and “The Mere” 46: each would run past a 40-wide board, so those two boards are widened, to 68 and 50. “Market”, 38 wide, and “Chapel”, 36, fit as they are.

Words on the boards

Each board gets its words as a World Text under it, so the words go where the board goes.

  1. Select sign-hut, press + Add node and choose World Text: the menu lists it after Sorting Group. Rename it sign-hut-words.
The Hierarchy with sign-hut selected, and the Add node menu open over it: Add child of sign-hut lit, Add as root, a box to type a filter, and the presets scrolled down to Line, Sprite Shape, Polygon, MultiMesh, Mesh, Clip, Sprite Mask, Sorting Group, World Text, lit under the pointer, Viewport, Screen Copy and Shader Material
+ Add node with sign-hut selected: World Text.

The preset’s words read Text, in white, in the project’s face, and stand on the node: its Offset is 0, 0.

  1. Type its Position -32, 0: on the board’s left edge, 2 in, since its words line up Left.
  2. In its WorldTextComponent, set each row from the first table below, and its three colours from the second. Drag fonts/kenney-high.ttf from Assets into the Font slot. Effect Mode and the five rows after it are in the Effects fold.
Fieldsign-hut-words
TextHollowmere
Scale0.5
Colorthe cream below
AlignLeft
Offset0, 0, as it comes
Pixel Sizeunticked
Sort LayerProps
Fontkenney-high.ttf
Unshadedunticked, as it comes
Effect ModeDistanceField
Outlinethe brown below
Outline Width1, as it comes
Shadowthe dark below
Shadow Offset1, 1, as it comes
Shadow Softness1
ColourTyped
Color, the cream0.93, 0.86, 0.66, alpha 1
Outline, the brown0.18, 0.10, 0.05, alpha 1
Shadow, the dark0, 0, 0, alpha 0.9
The Inspector on sign-hut-words: Name sign-hut-words, Position -32.0 and 0.0; its WorldTextComponent with Text Hollowmere, Scale 0.5, a cream Color, Align Left, Offset 0.0 and 0.0, Pixel Size unticked, Sort Layer Props and 5, Font kenney-high.ttf and Unshaded unticked; the Effects fold open: Effect Mode DistanceField, a brown Outline, Outline Width 1.0, a dark Shadow over a chequer, Shadow Off… 1.0 and 1.0 and Shadow Sof… 1.0, the last two labels cut short; Add component under it
sign-hut-words: its fifteen rows.
  1. Make the other three boards’ words the same way, each with its board selected first, from the table below: each one’s Position, Text and Align, the rest as sign-hut-words. Press Ctrl+S.
WordsPositionTextAlign
sign-hut-words-32, 0HollowmereLeft
sign-mere-words0, 0The MereCenter
sign-market-words0, 0MarketCenter
sign-chapel-words18, 0ChapelRight

Each Position is where its Align lines the words up: the board’s left edge, 2 in, for Left; its middle, where Add node leaves the words, for Center; its right edge, 2 in, for Right. The 2 keeps the words clear of the board’s outline. Drawn, “Hollowmere” runs from x 208 to 272 on a board from 206 to 274, and “Chapel” from 2802 to 2838 on one from 2800 to 2840.

  1. Select sign-hut-words, press Frame, and pick 400% from the zoom menu at the Viewport’s foot.
The editor at 400% round the hut’s signpost: a wooden board on its post reading HOLLOWMERE in cream capitals with a faint lighter brown rim, a box drawn round the words, their rim and shadow included, and no cross, the hut’s edge at the left and the town and the trees behind; the Hierarchy shows each of the four boards with its post and its words under it, sign-hut-words selected; the Inspector shows Position -32.0 and 0.0 and the WorldTextComponent with Text Hollowmere, Scale 0.5, Align Left, Sort Layer Props and Font kenney-high.ttf; the cursor row says at 208.0, -32.0 size 67.0, 13.0
A World Text in the Viewport: its box is its words.

A World Text is picked by its words and outlined round them: click the words in the Viewport to select it. Its box takes in their outline and shadow too, so it is a little wider and taller than the letters. Its node has no cross of its own.

The World Text’s Text
What it says. Enter starts a new line. The preset’s is Text; empty, it draws nothing.
The World Text’s Scale
How big the words are drawn: the face’s size times this. At 0.5, the signs’ 32-pixel face draws at 16 units: a line of it is 12 high, its letters 9. 1 as it comes.
The World Text’s Color
The words’ colour, alpha included: alpha 0 draws nothing, which is how the “+1” below fades. White as it comes, and typed in linear light, as every colour is.
The World Text’s Align: Left, Center or Right
Which edge of the words lines up with their place, the node’s place and the Offset. Left starts the words there and runs them right; Right ends them there; Center, as it comes, centres them on it.
The World Text’s Offset
How far from the node its words stand, in world units. The preset stands them on the node, 0, 0; a name tag lifts them over a head.
The World Text’s Pixel Size
Holds the words at one size on the screen however the camera zooms, as a name tag should. Ticked as it comes. The signs untick it: their words are part of the board, and grow and shrink with it.
The World Text’s Sort Layer
The sorting layer the words draw on, chosen by name, its number beside it: Props for the signs, over their boards on Ground and under him on Figures. Far, 1, as it comes.
The World Text’s Font
The face it draws in: a .ttf or .otf from Assets, at the size and with the field its import settings give. Empty, as it comes, draws in the project’s face.
The World Text’s Unshaded
Keeps the words at their colour under the room’s lights, as a sprite’s Unshaded does. Unticked as it comes. The crypt’s name tag ticks it, below.
The World Text’s Effect Mode: Copies or DistanceField
Copies, as it comes, draws the outline and the shadow as copies of the words, moved out round them and down beside them, in any face. DistanceField draws the words, their outline and their shadow in one pass from the face’s distance field, sharp at any zoom, and is the one that softens a shadow. It needs a face that bakes a field: the signs’ face does.
The World Text’s Outline and Outline Width
Outline is the colour of a line drawn round the letters, a see-through one drawing none; black as it comes. Outline Width is how far it reaches, in world units, 1 as it comes; 0 draws none.
The World Text’s Shadow, Shadow Offset and Shadow Softness
Shadow is the colour of a copy of the letters drawn behind them, see-through as it comes, so none is drawn. Shadow Offset is how far that copy is moved, 1, 1 as it comes: right and down. Shadow Softness blurs its edge, in world units, 0 as it comes; only DistanceField reads it, and under Copies it is greyed, with the reason.

The signs in the game

Press Run game and hold D until he stands by the mere’s sign. Its words stand on the board in the carved face: cream letters, a faint lighter brown rim round them, which is their outline, and a soft dark shadow down and to the right.

A part of the game, the mere’s sign close: a wooden board on its post reading THE MERE in cream capitals, a faint lighter brown rim round the letters and a soft dark shadow down and to the right of each
The mere’s sign, at the pixels the game draws it.

The words are drawn from the face’s own field, at the 32 px its settings give: on a copy whose words are in the project’s face instead, the picture differs round the words and nowhere else. And each sign’s words draw after its board and its post, so never under them.

The outline, typed 0.18, 0.10, 0.05, is lighter than the wood’s own numbers in every channel, so it shows as a paler rim.

Why DistanceField: the same sign on a copy whose words are on Copies, and on one whose Shadow Softness is 0.

The same part of the game on a copy whose words are on Copies: THE MERE with no soft shadow, the lighter rim round each letter, and a dark pixel at the lower right of some strokes
A copy on Copies: the outline and shadow drawn as copies of the words, and no soft shadow.
The same part of the game on a copy whose Shadow Softness is 0: THE MERE with a hard dark shadow down and to the right of each letter
A copy with Shadow Softness 0: the shadow’s edge hard.

With Softness 1 the shadow’s edge fades over a unit; at 0 it is cut hard, and the picture differs from the sign’s round its words and nowhere else.

Name tags

Each pilgrim gets a tag with his name, a World Text under him, so it goes where he goes.

  1. Select pilgrim, press + Add node and choose World Text. Rename it tag.
  2. Type its Text Pilgrim and its Offset 0, -40, so its words stand 40 above his feet, over his head, and set Sort Layer to Words. Leave the rest as it comes: Scale 1, white, Pixel Size ticked, the project’s face, Copies, and a black Outline 1 wide. Press Ctrl+S.
  3. Press Run game and hold D until he stands by the mere’s sign.
A part of the game by the mere: the wooden sign reading THE MERE on the left, and him at the right on the turf at the water’s edge, Pilgrim over his head in small white letters with a black edge; the town and the trees behind
By the mere’s sign, his tag over his head.

His tag rides on his head: as he walks, its words stay centred 40 above his feet on every frame, keeping their shape. It is in the project’s face, on Copies: black copies of its words, moved out round them, make its outline.

With Pixel Size ticked, the tag keeps its size on the screen whatever the camera’s zoom, and its outline keeps its width with it; the signs’ words, unticked, are drawn at the zoom. Here they are on a copy whose camera rig’s framing, follow, has Zoom 2, which draws everything twice as big, with him before the mere’s sign.

A part of the game on a copy whose camera is zoomed in twice as far: him large on the turf before the mere’s sign, the board and its THE MERE twice the size they were; over his head Pilgrim in small white letters with a black edge, at the size it was
A copy at Zoom 2: the sign drawn twice as big, the tag at its size on the screen.
  1. Double-click scenes/crypt.ron in Assets. Select its pilgrim, and give him a tag the same way. This one, tick Unshaded. Press Ctrl+S.
  2. With scenes/crypt.ron open, press F5: Play runs the open scene. Walk him east past the last torch, to the halls’ far end.
A part of the game in the crypt’s dark halls, away from the torches: him by the dark brick wall, Pilgrim over his head in bright white
Unshaded: the tag keeps its white in the dark.
The same part of the game on a copy whose tag is not Unshaded: Pilgrim over his head in a dim blue-grey
A copy with Unshaded unticked: lit as the walls are.

Away from the torches, only the crypt’s ambient light reaches him. The Unshaded tag’s brightest pixels are its Color, white; on a copy whose tag is lit, they are at least 30% darker.

A “+1”

The mere’s sign gets one more World Text, empty until he first passes it: then it reads “+1”, rises and fades. A script sets it off, through an Area that notices him.

  1. Press F5 again to stop. Double-click scenes/vale.ron in Assets, select sign-mere, press + Add node and choose World Text. Rename it plus-one. It stands at the board’s middle, where Add node puts it.
  2. Delete its Text, so it says nothing. Type its Color as the table below gives it, a pale gold, and its Offset 0, -24, and set Sort Layer to Words. Leave the rest as it comes.
Color
The “+1”1.0, 0.85, 0.3, alpha 1
  1. Press Add component and choose AreaComponent. In its Shape, type Size 48, 48 and leave Offset at 0, 0; leave the Area’s Layer and Mask as they come, pilgrim, as his.

The Area covers x 956 to 1004 and y -56 to -8: from 16 over the board’s top down into the reach of his own Area as he walks by.

  1. In Assets, click Assets in the path bar, so the script is written at the project’s top, then click Create, choose New script, type waymark and press Enter. Click the Code tab, then waymark.rgs in its Scripts list, replace everything in it with the script below, and press Ctrl+S. Click the Viewport tab.
  2. Drag waymark.rgs from Assets onto plus-one’s Inspector: it adds Waymark, its done unticked. Press Ctrl+S.
rgs waymark.rgs
/// The waymark on the mere's signpost. The first time the pilgrim walks
/// past the sign, a "+1" shows over it, rises and fades away. After that,
/// passing it shows nothing more.
component Waymark : Area {
    /// Whether the pilgrim has passed the sign already.
    #[readonly]
    done: bool = false,

    fn on_enter(other: NodeId) {
        // Something has come into the waymark's reach. Only the pilgrim, who
        // is in the group pilgrim, counts, and only the first time.
        if in_group(other, "pilgrim") && !done {
            done = true;
            // The words, empty until now, read +1.
            set_text("WorldTextComponent", "text", "+1");
            // Over a second they rise from 24 above the sign to 40 above it,
            // quickly at first and slowing as they arrive.
            anneal_point("WorldTextComponent", "offset", vec2(0.0, -40.0), 1.0, .OutCubic);
            // Over the same second they fade evenly, until nothing of them
            // is left to see.
            anneal_colour("WorldTextComponent", "color", vec4(1.0, 0.85, 0.3, 0.0), 1.0, .Linear);
        }
    }
}
component Waymark : Area
A script with an Area base: the Area on its node is the waymark’s reach, and on_enter runs when another Area comes into it, with that one’s node as other. His body carries an Area of its own, 12 by 30 on his feet.
#[readonly] and done
done is a field the script keeps, false as it comes. #[readonly] shows it greyed in the Inspector, to watch, not to type into. Once it is set, the if never passes again: the “+1” rises once.
in_group
Whether a node is in a group. The pilgrim is in pilgrim, so nothing else that comes by sets the “+1” off.
set_text
Writes text onto another component on this node: here the World Text’s text, its Text, from nothing to +1.
An anneal: anneal_point and anneal_colour
Each eases a field of another component on this node, from where it stands to the value it is given, over the seconds it is given, along a curve, and runs on by itself while the script goes on. Here the World Text’s offset, its Offset, from 24 above the sign to 40 above it, and its color, its Color, to the same gold at alpha 0, both over one second.
.OutCubic and .Linear
Curves, written with a leading point. .OutCubic is quick at first and slows as it arrives: the words shoot up and settle. .Linear is even: the words fade at one pace.
vec2 and vec4
Two numbers, here a place, and four, here a colour with its alpha.

Press Run game and hold D past the mere’s sign.

The game by the mere’s sign: he steps up to the sign from the west; a small pale gold +1 appears over the board, rises and fades away until nothing of it is left, while he stands by the sign, his tag over his head
Watch over the sign: the “+1” appears as he reaches it, rises, and is gone within a second.

Walked in from x 940, the “+1” is set off as his Area reaches the waymark’s. Half a second on it has risen and faded part of the way; a second and two steps on, it stands 40 above the sign, faded out, and nothing of it, its outline included, is left. Walked out and back, it stays as it ended, and walked back before it has ended, it is not set off again. Take && !done out of the script, and the same walk sets it off a second time.

The signposts

WhatSettings
fonts/kenney-high.ttfSize 32 px, Distance field On
The four boards and their postsColor 0.147, 0.064, 0.022, 1; Outline Color 0.033, 0.013, 0.005, 1; Outline 1; Ground
sign-hut, sign-mereSize 68, 16 and 50, 16
Each board’s wordsas sign-hut-words, each its own Position, Text and Align
tag, in both scenesText Pilgrim, Offset 0, -40, Words; the crypt’s Unshaded
plus-oneText empty, Color 1.0, 0.85, 0.3, 1, Offset 0, -24, Words; an Area 48 by 48; Waymark

Check it works