Skip to content

Development source guide ยท workspace 0.1.0

Time, input and game behavior

Game behavior needs a clear owner and a clear clock. A camera, physics body, UI button and player action can all refer to the same object, but they should not independently overwrite its state without a rule for which result wins.

The basic lifecycle

The standard application path takes a Game implementation. Its important responsibilities are:

Stage Your job
init Create initial objects, initial meshes and starting state; choose the view
update Read input, change game state and request actions
Optional physics Advance bodies and synchronize their transforms when the physics feature is enabled
Drawing Present the current state, using either the basic scene path or your custom drawing integration

The first-scene tutorial uses this basic path. Initial meshes are uploaded after init. Later scene changes can move an existing entity, but adding a CPU-side mesh in an update is not enough to upload a new GPU mesh.

game.toml supplies project metadata. It is not a universal scene file, a control map or a list of automatic settings. Window, camera and rendering behavior must be configured through the game's actual API or its own settings system.

Choose pressed, held or released input

A key being down is different from the moment it becomes down:

  • Use a held state for continuous actions, such as movement.
  • Use a just-pressed state for one action per press, such as accepting a menu choice.
  • Use a release state when the action specifically depends on releasing a control.

The engine tracks keyboard, mouse, gamepad and touch input, but each game decides what those inputs mean. Device support does not supply an inventory key, a working jump or a touch HUD automatically.

In the starter example, named_key("ArrowRight") supplies the key identifier and ctx.input.held(...) checks its current state. The checked key-name table is finite; not every imaginable platform key name is accepted by the harness.

Tip. A held key checked as an action trigger can repeat every update. If one press opens and immediately closes a menu, first check whether the game should use an edge-triggered input instead.

Express continuous movement as a rate

The first scene changes position by 2.0 * ctx.dt. That means two world units per second of update time, not two units every frame.

Without time scaling, a machine producing more updates can move farther in the same real interval. Time scaling does not by itself make all physics or game logic deterministic; random seeds, ordering, persistence and external input still matter.

The native control harness uses a fixed 1/60-second update time. This makes exact tick counts useful for reproducing a problem. It does not prove that every normal runtime path uses the same timing, or that every game will restore the same state from an incomplete snapshot.

Keep visual and physical movement consistent

A plain visual object can be moved by changing its transform. An object with an integrated physics body has another state owner: the physics world. In the standard linked update, physics runs after game update and synchronizes body transforms.

If you change only the visible transform of a physics-driven object, synchronization can overwrite your change. Decide whether the action is a visual move, a velocity/force change or a deliberate physics-body reposition, then use the corresponding integrated game behavior.

For a first control experiment, keep the object nonphysical as in the tutorial. Add collision and body integration after movement is understandable.

Window input and harness input

Normal window input depends on the runtime and window context. Harness injection changes the engine's input state directly; it is not a request to move the operating system's pointer or press a global key.

However, the harness does not fully isolate the game from people touching the keyboard or mouse. Real window events can still arrive. For a reproducible experiment, avoid interacting with the game while the script runs and release injected held controls explicitly.

A pressed-and-held harness key remains held until released. Disconnecting the client is not an automatic input reset. See inspection commands for safe press, step and release sequences.

Browser differences

Browser input is constrained by page focus and browser policy. Pointer lock needs a user gesture; Escape can release pointer lock rather than act like a native window control. Native exit requests are ignored by the web runner.

A canvas embedded in another page can have additional focus or pointer-lock restrictions. Test the actual hosted environment before promising that a native input recipe works unchanged in an embedded browser player.

Audio may also wait for interaction. Touch UI and mobile lifecycle behavior need game-specific work; a platform name in the specification is not evidence that those controls have been implemented.

Next, connect world and gameplay systems, or inspect a short input sequence before adding complexity.