Skip to content

Tutorials · Crypt Knight · Chapter 8

Signs

40 minutes Uses: Area, Shape, WorldText, TileMap, in_group, anneal_colour

By the end

  • The knight with an Area of his own and a group, knight, so a tablet can notice him and know him
  • Five pedestals painted on the tilemap’s back layer
  • A script, sign.rgs, that fades a tablet’s panel and words in while the knight is in its Area and out when he leaves
  • Five tablets along the Gate: walk, jump, jump higher, drop down and spikes
On this page

The knight is noticed

A tablet notices the knight when the knight walks into its trigger, and in Rengy it is Areas that notice Areas: a shape that overlaps another, whose script then hears about it. A body does not count, so the knight needs an Area of his own. And since a tablet may be walked into by anything one day, a skeleton or a fireball, the knight also gets a group, a name a script can ask about.

  1. Select knight. Under Groups, type knight and press Enter. The Hierarchy shows it as a tag beside his name.
  2. Press Add component and choose AreaComponent.
  3. Open its Shape, and set Size to 12 and 30 and Offset to 0 and -15: the same box as the body’s, standing on the node’s position, the knight’s feet. Leave Kind on Rectangle.
  4. Click the Mask row, and untick the one layer it names, 0, so it reads Nothing. Leave the Area’s own Layer at 0.
  5. Press Ctrl+S.
The knight selected, its Inspector narrowed to its Area: Shape Rectangle, Size 12 by 30, Offset 0 and -15, Layer 0 and Mask Nothing; in the Viewport the Area’s outline lies over the knight on the body’s green box, the same 12 by 30, with a small dot at its centre for the Offset and a square grab on each of the box’s top corners
Layer and Mask
Which layer an Area is on, and which layers it looks for. A tablet looks for layer 0, which every Area is on until you say otherwise, so it notices the knight. The knight’s Area looks for none: it is noticed, and it never hears about a tablet, which it has no use for.

Pedestals for the tablets

A tablet stands on a pedestal of stone, two cells of the castle’s tile sheet: a capped top, #48, over its brick, #69. They are scenery, so they go on the tilemap’s back layer, which stops nothing and draws behind the knight.

  1. Select ground, open the Tilemap tab, turn on Paint mode, and choose Brush. Under Layers, click back.
  2. In the picker, hover until the tooltip reads #48, the sixth tile of the third row, and click it. Click once inside each of the five cells in the first column of the table below.
  3. Pick #69, the sixth tile of the fourth row, straight under it, and click once inside each of the five cells in the second column.
  4. Press Save at the top of the Tilemap panel.
TabletCap, #48, at cellBrick, #69, at cell
sign_walk(5, 8)(5, 9)
sign_jump(11, 8)(11, 9)
sign_high(21, 7)(21, 8)
sign_drop(45, 5)(45, 6)
sign_spikes(57, 8)(57, 9)
The Tilemap panel in Paint mode with the Brush, over the Gate’s left end through the game camera: a grid over the room, and two stone pedestals standing on the floor, one in the first third of the view and one on the step’s edge

Each pedestal stands on a floor or a ledge you painted in chapter 4: the first two on the start floor, the third on the step, the fourth on the ledge over the drop, and the last on the lower floor before the spike pit. The back layer does not collide, so nothing about the knight’s walk changes.

The sign’s script

A tablet’s script has one job: when the knight comes into its Area, fade its panel and its words in, and when he leaves, fade them out.

  1. In Assets, press Create, choose New script, type sign, and press Enter.
  2. In the Code tab’s Scripts list, click sign.rgs, replace everything in it with the script below, and press Ctrl+S.
rgs sign.rgs
/// A sign: its panel and words fade in while the knight is near, and out when
/// it leaves.
component Sign : Area {
    /// Seconds to fade in or out.
    #[suffix("s")]
    fade: f32 = 0.25,

    fn on_enter(other: NodeId) {
        if in_group(other, "knight") {
            anneal_colour("ShapeComponent", "color", vec4(0.05, 0.05, 0.08, 0.85), fade, .Linear);
            anneal_colour("WorldTextComponent", "color", vec4(1.0, 0.94, 0.8, 1.0), fade, .Linear);
            anneal_colour("WorldTextComponent", "outline", vec4(0.0, 0.0, 0.0, 1.0), fade, .Linear);
        }
    }

    fn on_exit(other: NodeId) {
        if in_group(other, "knight") {
            anneal_colour("ShapeComponent", "color", vec4(0.05, 0.05, 0.08, 0.0), fade, .Linear);
            anneal_colour("WorldTextComponent", "color", vec4(1.0, 0.94, 0.8, 0.0), fade, .Linear);
            anneal_colour("WorldTextComponent", "outline", vec4(0.0, 0.0, 0.0, 0.0), fade, .Linear);
        }
    }
}
The Code panel open on sign.rgs, the Sign component: a fade of 0.25 seconds, and the on_enter and on_exit hooks, each fading three colours, with Up to date in its status line
component Sign : Area
A script with an Area base. The Area of the node it is on is the tablet’s trigger, and the script hears what that Area meets: on_enter when another Area comes into it, on_exit when it leaves, each with the other’s NodeId.
in_group
Whether the node other is in a group. The tablet fades only for the knight, which the group says he is. A skeleton walking by would not light it.
anneal_colour
Eases a colour field of one of this node’s components to a value over a time: here to the panel’s color, the words’ color and the words’ outline, over fade seconds, .Linear. In: a dark panel, 85% opaque, warm white words, a black outline. Out: the same colours, with their alpha at 0.
fade
A field, 0.25 seconds, which is a row in the Inspector. The /// line over it is its tooltip.

The first tablet

A tablet is one node with four components: a Shape for its panel, a World Text for its words, an Area for its trigger, and the Sign script. Build the first, and the other four are copies of it.

  1. Select Gate, press + Add node, choose Shape, and rename it sign_walk. Set its Position to 88 and 114: the middle of its pedestal, in cell 5 across, and a little over it.
  2. In its Shape, set Size to 92 and 13, Outline to 0 and Sort Layer to 8. Set Color to 0.05, 0.05, 0.08 with an alpha of 0: a dark panel you cannot see yet.
  3. Press Add component and choose WorldTextComponent. Set Text to A / D to walk., Offset to 0 and 0, and Sort Layer to 9, over the panel.
  4. Set its Color to 1, 0.94, 0.8 with an alpha of 0, and, in its Effects, its Outline to 0, 0, 0 with an alpha of 0.
  5. Press Add component and choose AreaComponent. In its Shape, set Size to 48 and 56, and Offset to 0 and 18. Leave Layer and Mask as they are.
  6. Press Add component and choose Sign, and keep its Fade at 0.25.
  7. Press Ctrl+S.
The sign_walk node’s Inspector narrowed to its Shape: Kind Rectangle, Size 92 by 13, Anchor 0.5 and 0.5, a see-through Color, Outline 0 and Sort Layer Custom, 8
The sign_walk node’s Inspector narrowed to its World Text: Text “A / D to walk.”, Scale 1, a see-through Color, Align Center, Offset 0 and 0, Pixel Size ticked, Sort Layer Custom, 9, no Font, Unshaded unticked, and Effects with Effect Mode Copies, a see-through Outline of Width 1, a see-through Shadow, Shadow Offset 1 and 1, and Shadow Softness dimmed
The sign_walk node’s Inspector narrowed to its Area: a Rectangle Shape of Size 48 by 56 and Offset 0 and 18, Solid and One Way unticked, Layer 0 and Mask 0
The panel
A rectangle behind the words: the text’s width in pixels, six for each character, with a margin of eight, by 13 tall. Its Color has an alpha of 0 until the knight comes, and the script raises it.
The words
The built-in 5 by 9 pixel face, with a clear outline the script fills in. A sign’s Sort Layer is 9, one over its panel’s 8, and both are over the knight’s 5, so the words are not hidden by him.
The Area
A box 48 across and 56 tall, reaching from just above the panel down to the floor the pedestal stands on, so the knight is in it while he walks past, jumps beside it, or stands at its foot.

Four more

The other four differ from the first in where they stand, and in what they say and so how wide their panel is.

  1. Right-click sign_walk in the Hierarchy and choose Duplicate. Rename the copy sign_jump, and set its Position, the Text of its World Text and the Size of its Shape from the table below.
  2. Do the same for sign_high, sign_drop and sign_spikes.
  3. For sign_spikes, also set the Area’s Offset to 0 and 23, and press Enter in its Text between the lines, so it reads on two.
  4. Press Ctrl+S.
NodePositionTextPanel sizeArea offset
sign_walk88, 114A / D to walk.92, 130, 18
sign_jump184, 114Space to jump.92, 130, 18
sign_high344, 98Hold Space to jump higher.164, 130, 18
sign_drop728, 66Hold S and jump to drop down.182, 130, 18
sign_spikes920, 109Spikes hurt -- and, on the next line, you'll be back on safe ground.188, 230, 23

Each tablet stands where it teaches. sign_jump is against the step it explains, and sign_high on the step, under the tall ledge a tap cannot reach. sign_drop is on the one-way ledge, where S and Space take the knight down through it, and sign_spikes is before the pit that, in chapter 9, gets spikes. The text is two lines, and has -- where a dash would go, because the built-in face has no long dash.

What comes next

You have the Gate: a level of stone in one tilemap and four layers of night town, a knight who runs, jumps high and low, drops through a ledge and wears his own art, a camera that follows him, and five signs that tell a player how. Nothing in it can hurt him yet. Chapter 9 gives it teeth: spikes, a gap with no floor, five hearts and a HUD to show them, and a blink and a shake when he is hurt.

Check it works

The knight against the step with his cape behind him, and over him, in a dark panel, the words “Space to jump.”
The knight on the step beside the tall ledge, and over him the words “Hold Space to jump higher.” on a dark panel