Learn moveby

Scenes in moveby-lang

A scene is a program in moveby-lang, a small language over numbers. This page covers the part of the language that a scene needs: its inputs, its camera, its objects, and WHEN. The program has no clock, no state and no loop of its own. It maps the numbers your page gives to the numbers the engine draws.

Inputs: dynamic and using

dynamic { … } names the numbers your page gives every frame. using { … } names the numbers it gives once, when the scene loads. A name can sit in a group, and a group is a dotted path: lamp.start.

scene.moveby
// Numbers the page gives every frame: position is required; hover is the page's own.
dynamic { position, hover }

// Numbers the page gives once, at load: an asset group, and one group of its own.
using { moveby { asset { tree } }, lamp { start, stop } }

// The camera stands 2 m up, hover metres to the side. The page's lamp.start lifts it.
out field camera_x = hover
out field camera_y = 2 + lamp.start

object tree_1 = image(moveby.asset.tree) {
    x = 12, y = 0, z = lamp.stop, yaw = 0, pitch = 0, roll = 0,
    scale = 1, origin_x = 0.5, origin_y = 0
}
  • position is a fixed name. Every scene declares it, because the camera needs it.
  • The build writes the dynamic names into track.d.ts as a type, so TypeScript checks every scene.draw call. A using name that is not an asset becomes a key of the using option of loadTrack.
  • moveby.asset.<name> is the group of looks. Your page gives each one with asset(name, …): a cell of the sprite atlas, and a size in metres.

The camera: out field

An out field is a number the scene gives to the engine. A scene has two: camera_x, how far to the side of the route the camera stands (positive is right), and camera_y, how high above the road. The camera stands position metres along the route and faces along it.

Any other out field is an error. A helper value is a let.

Terminal
$ npx moveby build scene.moveby road.json
scene.moveby  SCENE_NAME  An out field of the scene is not camera_x or camera_y. (sun_height)

Objects: image and text

An object is one thing that stands in the world. Its kind is a call: image(moveby.asset.tree) places a look from your sprite atlas, and text("MOVEBY") writes a sign. The properties are one block of name = value pairs. Each is an expression of the inputs, so any of them can move.

scene.moveby
dynamic { position, time }
using { moveby { asset { tree } } }

out field camera_x = 0
out field camera_y = 2

// An image: a look from the page, placed in world space. Every property is required.
object tree_1 = image(moveby.asset.tree) {
    x = 8, y = 0, z = 30,           // metres: +x right, +y up, +z forward
    yaw = 0, pitch = 0, roll = 0,   // degrees; yaw is positive clockwise, like turn
    scale = 1,                      // 0 hides the object; below 0 is an error
    origin_x = 0.5, origin_y = 0    // the point it turns about, in 0..1 of the card
}

// A sign: the text is the kind's argument. Every property is required too.
object sign = text("MOVEBY") {
    x = 0, y = 5, z = 40, yaw = 0,
    alpha = 1,                      // 0 to 1
    height = 2,                     // metres
    color_r = 1, color_g = 0.8, color_b = 0   // each 0 to 1
}
  • Objects use world space, in metres: +x is right, +y is up and +z is forward. The route starts at the origin and faces +z.
  • An object lists every property of its kind. If you leave one out, or add one, the build stops and names it.
  • yaw is positive clockwise, like turn in the road file.
  • A scale or a height of 0 hides the object. A value below 0, or outside a property's range, stops the frame with SCENE_VALUE.
Pitfall

Numbers have no units. Write 20, not 20m: the language reads 20m as 20 times a value named m, and the build stops.

Terminal
$ npx moveby build scene.moveby road.json
scene.moveby  SCENE_COMPILE  m - unknown name `m`

Conditions: WHEN

WHEN condition { … } assigns a property while the condition holds. When it stops holding, the property goes back to the value of its object. Inside the block, delta time is the time since the condition became true. That is the one thing a scene remembers.

scene.moveby
dynamic { position, time }
using { moveby { asset { tree } } }

out field camera_x = 0
out field camera_y = 2

object tree_1 = image(moveby.asset.tree) {
    x = 8, y = 0, z = 30, yaw = 0, pitch = 0, roll = 0,
    scale = 1, origin_x = 0.5, origin_y = 0
}

// While the condition holds, the assignment replaces the value above.
WHEN position > 20 { tree_1.scale = 2 }

// delta time is the time since the condition became true: here the tree turns 90° over 2 s.
WHEN position > 40 { tree_1.yaw = interpolate delta time: 0..2 -> 0..90 [gentle] }

interpolate delta time: 0..2 -> 0..90 [gentle] maps the first 2 seconds after the trigger to 0°…90°, with an easing. scene.reset() forgets every trigger, for a replay from the start.