AURA

JSGG

AuraJS
DOCSEXAMPLESGITHUB
02 Window, Input, and 2D Camera
Window sizing, fullscreen, input polling, action maps, and 2D camera controls.
docs/external/game-dev-api/02-window-input-and-2d-camera.md

Window, Input, and 2D Camera

These are the core environment/control surfaces most games hit first.

`aura.window`

Current surface:

  • setTitle(title)
  • setSize(width, height)
  • setFullscreen(enabled)
  • getSize()
  • getPixelRatio()
  • getFPS()
  • setCursorVisible(visible)
  • setCursorLocked(locked)
  • setCursor(cursor)
  • screenshot(path?)
  • minimize()
  • restore()
  • focus()
  • close()

Compatibility/read-only fields commonly present:

  • aura.window.width
  • aura.window.height
  • aura.window.pixelRatio
  • aura.window.fps

Use cases:

  • resize and fullscreen control
  • cursor lock for shooters and 3D camera rigs
  • window diagnostics and screenshots

FPS lifecycle notes:

  • setCursorVisible(...) and setCursorLocked(...) are separate controls; call both explicitly for FPS camera rigs.
  • Entering or leaving cursor lock clears the current-frame getMouseDelta() result so the first locked/unlocked frame does not replay stale motion.
  • aura.onBlur and aura.onFocus do not implicitly change cursor lock or visibility preference; if your game should unlock on blur, do it in aura.onBlur().

`aura.input`

Core keyboard/mouse/gamepad methods:

  • isKeyDown(key)
  • isKeyPressed(key)
  • isKeyReleased(key)
  • getMousePosition()
  • getMouseDelta()
  • isMouseDown(button)
  • isMousePressed(button)
  • getMouseWheel()
  • isGamepadConnected(index?)
  • getGamepadAxis(axis, index?)
  • isGamepadButtonDown(button, index?)

Compatibility aliases:

  • isDown(...)
  • isPressed(...)
  • isReleased(...)

Bridged helper views exposed for convenience:

  • aura.input.mouse.x
  • aura.input.mouse.y
  • aura.input.mouse.scroll
  • aura.input.mouse.getDelta()
  • aura.input.mouse.isDown(button)
  • aura.input.mouse.isPressed(button)
  • aura.input.mouse.isReleased(button)
  • aura.input.gamepad.connected
  • aura.input.gamepad.axis(name)
  • aura.input.gamepad.isDown(button)
  • aura.input.gamepad.isPressed(button)
  • aura.input.gamepad.isReleased(button)
  • aura.input.actionMap

Use cases:

  • raw keyboard/mouse polling
  • gamepad support
  • action remapping helpers layered on top of raw input

Mouse-delta note:

  • getMouseDelta() is the canonical relative-look primitive. Lock/unlock and blur/focus transitions clear the current-frame delta before game code observes it.

For first-person games, treat cursor lock plus relative delta as one explicit control path:

let lookLocked = false;
let yawDeg = 0;
let pitchDeg = 0;

function setLookLocked(locked) {
  aura.window.setCursorLocked(locked);
  aura.window.setCursorVisible(!locked);
  lookLocked = locked;
}

aura.onBlur = function onBlur() {
  if (lookLocked) setLookLocked(false);
};

aura.onQuit = function onQuit() {
  if (lookLocked) {
    setLookLocked(false);
    return false;
  }
  return true;
};

aura.update = function update() {
  if (!lookLocked && aura.input.isMousePressed('left')) {
    setLookLocked(true);
    return; // consume the click that entered lock
  }

  if (!lookLocked) return;

  const delta = aura.input.getMouseDelta();
  yawDeg -= delta.x * 0.14;
  pitchDeg = Math.max(-89, Math.min(89, pitchDeg - (delta.y * 0.14)));
};

Recommended rules:

  • Call setCursorLocked(...) and setCursorVisible(...) together. Do not rely on one to imply the other.
  • Consume the click that entered cursor lock so the first lock frame does not also fire a shot, placement, or interaction.
  • Unlock on aura.onBlur() if your game should return the cursor to the OS when focus leaves the window.
  • If you intercept quit while locked, unlock first and return false so the first Esc cancels lock instead of closing the game.
  • Treat arrow-key or absolute-mouse look as a compatibility fallback only. The supported FPS path is getMouseDelta() while locked.

`aura.camera` (2D camera)

The 2D camera is a stateful helper over immediate-mode 2D drawing.

State fields commonly used directly:

  • aura.camera.x
  • aura.camera.y
  • aura.camera.zoom
  • aura.camera.rotation

Methods:

  • getState()
  • follow(target, options?)
  • stopFollow()
  • setDeadzone(x, y, width, height)
  • clearDeadzone()
  • setBounds(x, y, width, height)
  • clearBounds()
  • pan(...)
  • panTo(...)
  • zoomTo(...)
  • rotateTo(...)
  • shake(...)
  • clearEffects()
  • onEffectComplete(callback, order?)
  • offEffectComplete(callbackId)
  • update(dt)

Use cases:

  • player follow cameras
  • platformer deadzones
  • cinematic pans, zooms, shakes, and camera bounds

Notes for agents and tooling

  • Prefer canonical names like isKeyDown over compatibility aliases in generated code.
  • Prefer aura.camera for game camera state instead of carrying your own global transform unless you need custom math.
  • If you need 3D camera controls, use aura.camera3d instead of this namespace.
DOCUMENT REFERENCE
docs/external/game-dev-api/02-window-input-and-2d-camera.md
AURAJS
Cmd/Ctrl+K
aurajsgg