Types
ActionState
interface ActionState
From @phaser-ae/kernel
A named action's state in this step.
readonly held: boolean— Any bound code is down right now.readonly pressed: boolean— Went down since the last step (latched, so a tap between two steps is still seen, for exactly one step).readonly released: boolean— Came up since the last step (latched the same way).
GamepadState
interface GamepadState
From @phaser-ae/kernel
One gamepad slot, polled once per frame.
readonly index: number— The slot's index innavigator.getGamepads().readonly connected: boolean— Is a pad present in this slot.axis(name: 'lx' | 'ly' | 'rx' | 'ry' | 'lt' | 'rt'): number— A standard-mapping axis: sticks -1..1 (down is positive only/ry) with a 0.15 dead zone rescaled away; triggerslt/rt0..1.button(name: string): boolean— Is a standard-mapping button down:a b x y lb rb lt rt back start ls rs up down left right. Unknown names are false.
GestureHandlers
interface GestureHandlers
From @phaser-ae/kernel
Gesture handlers; any may return false to stop propagation to lower layers.
onTap?(e: TapEvent): void | false— A press released within the tap limits.onDoubleTap?(e: TapEvent): void | false— A second tap within the double-tap limits; the first still firesonTap.onLongPress?(e: TapEvent): void | false— A press held pastlongPressDelaywithout moving; the release is then neither tap nor swipe.onPan?(e: PanEvent): void | false— A drag:start, thenmoveper pointer event, thenend.onSwipe?(e: SwipeEvent): void | false— Fired after a pan'sendwhen it was long and fast enough.
GestureOptions
interface GestureOptions
From @phaser-ae/kernel
Gesture recognition thresholds. Seconds and logical pixels.
tapMaxDuration?: number— Longest press that still counts as a tap, seconds; default 0.25.tapTolerance?: number— Furthest a tap may move from where it began, px; default 8.doubleTapDelay?: number— Longest gap between two taps for a double tap, seconds; default 0.3.doubleTapDistance?: number— Furthest apart two taps may be for a double tap, px; default 16.longPressDelay?: number— Hold before a long press fires, seconds; default 0.6.longPressTolerance?: number— Furthest a long press may drift before it is cancelled, px; default 8.swipeMinDistance?: number— Shortest pan, on release, that also counts as a swipe, px; default 20.swipeMinVelocity?: number— Slowest pan, on release, that also counts as a swipe, px/s; default 300.panThreshold?: number— Movement before a press becomes a pan, px; default 4.
Input
interface Input
From @phaser-ae/kernel
The input service: polled state for a rig or a step, routed events for a shell or UI.
readonly gameplay: Input— The player's view, which isgame.input: it reads nothing while the game is paused or a capture is held, and never sees a key or pointer ashelloruiconsumer claimed. Actions, pointers and key presses keep the scene-entry grace;keyDowndoes not. The raw input stays available to UI and debug code.captureWorld(): Cancel— Take the world's input, for a modal (a dialogue, a menu): world events and the player's view read nothing until the returned token is cancelled. Keys and pointers held when it began stay unseen by the world until released, so nothing replays when it ends.cancelHeld(): void— Release every held key and pointer drag, and drop typed text and pending edges. The kernel calls it on blur, a hidden page and stop.consume(layer: InputLayer, c: InputConsumer): Cancel— Subscribe a consumer at a layer. Order within a layer is subscription order.keyDown(code: string): boolean— Is the key with thisKeyboardEvent.codedown right now.keyPressed(code: string): boolean— Did this key go down THIS STEP — the raw-code edge, and the sibling ofkeyDown. It holds until a step actually consumes it, so a tap that starts and ends between two fixed steps is still seen; at 240 Hz on a 60 Hz sim that is most taps. Ongame.input(the player's view) it is muted by the scene-entry grace, as actions are, so a key mashed as the player dies does not dismiss the screen that follows. The rawgame.kernel.inputkeeps no grace: that is for a debug toggle or a tool.keyReleased(code: string): boolean— Did this key come up this step. The other half ofkeyPressed.press(code: string, down: boolean): void— Press or release a key CODE from code rather than from the keyboard, so anything that is not a keyboard can drive the same bindings: on-screen touch buttons, a remote pad, a scripted demo, an AI driver. Use a code no keyboard has ('Touch:jump') and bind it alongside the real ones.bind(name: string, codes: ReadonlyArray<string>): void— Bind key codes to a named action (bind('jump', ['Space', 'KeyW'])); the action is held while ANY code is. Rebinding replaces.unbind(name: string): void— Remove an action;action(name)then throws.action(name: string): ActionState— A named action'sheld,pressedandreleasedin this step. An unbound name throws, listing the bound ones.readonly text: string— Typed text since the last step (layout-resolved characters, in order), for name entry and chat. Backspace and Enter arrive as key codes, not here. Keys typed into a page's own text field are not the game's. It is CONSUMED by the first fixed step of a frame, exactly aspressededges are: a frame that has to catch up on four steps would otherwise type everything four times. And it is carried over frames no step ran in at all, so nothing typed is lost at a high refresh rate.readonly wheel: number— Wheel movement since the last step, summedWheelEvent.deltaY(positive when scrolling down).gestures(layer: InputLayer, handlers: GestureHandlers, opts?: GestureOptions): Cancel— Subscribe to gestures at a layer: tap, double tap, long press, pan, swipe. Handlers run as the events arrive, outside the fixed step; within the grace window none fire. The tap, double-tap, long-press and swipe thresholds are read from the first live subscription, so passoptsthe same everywhere;panThresholdis per subscription.readonly pointer: PointerState | null— The first pointer the game knows, or null when none: a mouse counts while it hovers, a finger only until its release has been seen.readonly pointers: ReadonlyArray<PointerState>— Every pointer the game knows; a fresh array each read.readonly gamepads: ReadonlyArray<GamepadState>— Every gamepad slot the browser has reported, connected or not; empty headless and until a pad is seen.readonly touchDevice: boolean— The device reports touch support. Set when input attaches to the canvas; false headless.ignoreFor(seconds: Seconds): void— Ignore player input — actions, pointers, gestures — forseconds.keyDownis NOT gated: that is what a dev overlay's toggle and a host shell read, and a debug key that dies for a quarter of a second after every scene change is a bug report. Applied automatically on every scene entry (inputGrace, default 0.25s): a player frantically tapping fire as they die must not instantly dismiss the game-over screen they have not read yet. Extends, never shortens.readonly ignoring: boolean— True while a grace window is running: actions, pointers, gestures and the player's key presses read inactive.requestPointerLock(): void— Ask the browser to lock the pointer to the canvas. Needs a user gesture; no-op headless.exitPointerLock(): void— Release pointer lock.readonly pointerLocked: boolean— Is the pointer locked to the canvas right now.
InputConsumer
interface InputConsumer
From @phaser-ae/kernel
What a layer subscribes with; either handler may be absent.
pointer?(e: PointerEvent): void— Every pointer event not claimed above.key?(e: KeyEvent): void— Every key event not claimed above.
InputLayer
type InputLayer = 'shell' | 'ui' | 'world'
From @phaser-ae/kernel
A consumer layer, top first: shell (the page's own controls), ui (menus, buttons), world (play).
KeyEvent
interface KeyEvent
From @phaser-ae/kernel
A key event as routed to consumers.
readonly code: string—KeyboardEvent.code: the physical key, whatever the layout ('KeyW','Space','ArrowUp').readonly type: 'down' | 'up'— Down or up.readonly repeat: boolean— An auto-repeat of a held key.claim(): void— Stop delivery to the consumers after this one and to every lower layer.
PanEvent
interface PanEvent extends TapEvent
From @phaser-ae/kernel
A drag in progress; x/y is the current position.
startX: number— Where the press began, logical px.startY: number— Where the press began, logical px.dx: number— Movement since the last pan event, px.dy: number— Movement since the last pan event, px.totalX: number— Movement since the press began, px.totalY: number— Movement since the press began, px.phase: 'start' | 'move' | 'end'—startonce the pan threshold is crossed,moveper event,endon release.
PointerEvent
interface PointerEvent extends PointerState
From @phaser-ae/kernel
A pointer event as routed to consumers: the pointer's state plus what just happened.
readonly dx: number— Movement since the previous native event for this pointer (not since the last step, as when polled).readonly dy: number— Movement since the previous native event for this pointer.readonly type: 'down' | 'up' | 'move' | 'cancel' | 'wheel'— What happened.cancelis the pointer taken away: the browser'spointercancel, lost capture, a blur, a hidden page. A wheel event's pointeridis -1.readonly deltaY?: number— Wheel events only:WheelEvent.deltaY, positive when scrolling down.claim(): void— Stop delivery to the consumers after this one and to every lower layer.
PointerState
interface PointerState
From @phaser-ae/kernel
One pointer (mouse, finger or pen) as polled in a step. All coordinates in logical screen pixels.
readonly id: number— Browser pointer id; -1 for wheel events.readonly x: number— Logical screen pixels; worlds convert to world units.readonly y: number— Logical screen pixels; worlds convert to world units.readonly down: boolean— Is a button or finger currently pressed.readonly pressed: boolean— Went down since the last fixed step (latched: true for exactly one step even if the press and release fell between two steps). A single tap never slips through.readonly released: boolean— Went up since the last fixed step (latched the same way).readonly button: number— Button of the current press: 0 left, 1 middle, 2 right.readonly kind: 'mouse' | 'touch' | 'pen'— What kind of device this pointer is.readonly startX: number— Where the current press began, logical px.readonly startY: number— Where the current press began, logical px.readonly dx: number— Movement accumulated since the last fixed step, logical px.readonly dy: number— Movement accumulated since the last fixed step, logical px.readonly vx: number— Velocity over the last ~80 ms, logical px/s: a flick can be thrown without a swipe threshold.readonly vy: number— Velocity over the last ~80 ms, logical px/s.readonly downTime: number— Seconds the current press has been held (0 when up).readonly isTouch: boolean—kind === 'touch', for the common check.
SwipeDirection
type SwipeDirection = 'up' | 'down' | 'left' | 'right'
From @phaser-ae/kernel
The dominant axis of a swipe.
SwipeEvent
interface SwipeEvent extends TapEvent
From @phaser-ae/kernel
A fast pan released past the swipe thresholds; x/y is where it ended.
direction: SwipeDirection— Dominant axis.distance: number— Length of the whole pan, px.velocity: number— Speed at release, px/s.angle: number— Direction of the whole pan in radians, fromatan2(totalY, totalX).
TapEvent
interface TapEvent
From @phaser-ae/kernel
A tap, double tap or long press.
x: number— Where it happened, logical px.y: number— Where it happened, logical px.id: number— The pointer that did it.kind: PointerState['kind']— Device kind of that pointer.
