Input Layers¶
Input layers let you control which part of your game receives input first. When a dialog is open, it should consume input before the game logic sees it.
Quick Start¶
public class GameScene : Scene
{
private readonly InputLayerManager _layerManager;
public GameScene(InputLayerManager layerManager)
{
_layerManager = layerManager;
}
protected override void OnEnter()
{
var uiLayer = _layerManager.CreateLayer(""UI"", priority: 1000);
var gameLayer = _layerManager.CreateLayer(""Game"", priority: 0);
}
protected override void OnUpdate(GameTime gameTime)
{
_layerManager.ProcessInput();
if (!_layerManager.KeyboardConsumed)
{
HandleGameKeyboard();
}
if (!_layerManager.MouseConsumed)
{
HandleGameMouse();
}
}
}
How It Works¶
- Layers are processed by priority — highest first
- A layer can consume input — returning
trueblocks lower layers - Check consumption flags —
KeyboardConsumed,MouseConsumed
Typical priorities:
| Layer | Priority | Purpose |
|---|---|---|
| Dialog/Modal | 2000 | Critical UI |
| Normal UI | 1000 | Menus, HUD |
| Game | 0 | Player input |
| Background | -1000 | Ambient input |
Best Practices¶
- Always call
ProcessInput()first inOnUpdate - Check consumption flags before handling game input
- Return
truefrom layer handlers to consume input - Unregister layers in
OnExitorOnUnloadAsync
protected override void OnUpdate(GameTime gameTime)
{
_layerManager.ProcessInput(); // Always first!
if (!_layerManager.KeyboardConsumed && Input.IsKeyDown(Key.W))
{
MovePlayer();
}
}
Next Steps¶
- Keyboard Input — Keyboard input handling
- Mouse Input — Mouse and cursor control
- UI — Build interactive UI