Skip to content

Input Handling

FroglightInteractive edited this page May 5, 2026 · 2 revisions

Input Handling

NovaEngine provides a simplified wrapper around keyboard state via the NovaInput static class.

NOTE: Mouse input/handling is W.I.P and coming soon

Keyboard Input

Checking Single Keys

You can check if a key is currently held down, if it was just pressed this frame, or if it was just released this frame.

if (NovaInput.IsKeyPressed(NovaInput.Keys.Space))
{
  // Happens every frame the key is held
  player.Jump();
}

if (NovaInput.WasKeyJustPressed(NovaInput.Keys.Escape))
{
  // Happens only ONCE when the key is first hit
  ToggleMenu();
}

if (NovaInput.WasKeyJustReleased(NovaInput.Keys.Space))
{
  // Happens only ONCE when the key is first released
  player.CutJump();
}

The Axis Shortcut (2-Way Movement)

NovaInput includes GetAxis. This returns a float, perfect for platformer movement.

protected override void OnUpdate(float dt)
{
  // Get direction from A/D keys
  float moveDir = NovaInput.GetAxis(NovaInput.Keys.A, NovaInput.Keys.D);

  // Apply speed and DeltaTime
  player.Velocity.X = moveDir * 300f;
}

The Vector Shortcut (4-Way Movement)

NovaInput includes GetVector. This returns a normalized Vector2, perfect for top-down movement. It automatically handles the math so diagonal movement isn't faster than cardinal movement.

protected override void OnUpdate(float dt)
{
  // Get direction from WASD keys
  Vector2 moveDir = NovaInput.GetVector(NovaInput.Keys.A, NovaInput.Keys.D, NovaInput.Keys.W, NovaInput.Keys.S);

  // Apply speed and DeltaTime
  player.Velocity = moveDir * 300f;
}

Best Practices

  1. Use dt with input: When moving an object based on input, always multiply by dt (Delta Time) in your update loop to ensure consistent speed across different monitors.
  2. Normalized Vectors: Since GetVector returns a normalized vector (length or 1), you can simply multiply it by a speed variable to get your desired velocity.
  3. Key Enums: NovaEngine uses its own NovaInput.Keys enum for all key checks.

Clone this wiki locally