Skip to content

dpad

A directional pad for stepwise movement. Choose 4 directions (up/down/left/right) or 8 (adds the four diagonals). Emits press when a direction starts and release when the player lifts off.

C# factory

WidgetDefinitions.Dpad(
id: "dpad",
positionX: 0.15f, positionY: 0.7f,
directions: 4
);

Wire format

FieldTypeRequiredNotes
idstringyes
type"dpad"yes
position_x, position_ynumberno0..1 anchor.
directions4 | 8noDefault 4.

Events

Event typePayloadFires when
press{ direction: string }Direction starts. Repeats with the new direction if the player drags from one to another.
release{}Player lifts off.

direction is one of up, down, left, right. With 8 directions, also up-left, up-right, down-left, down-right.

Example

manager.OnInput += (player, evt) =>
{
if (evt.WidgetId != "dpad") return;
if (evt.EventType == "press")
{
switch (evt.GetString("direction"))
{
case "up": transform.Translate(Vector3.forward); break;
case "down": transform.Translate(Vector3.back); break;
case "left": transform.Translate(Vector3.left); break;
case "right": transform.Translate(Vector3.right); break;
}
}
};