- Android
- iOS
- Web
Game View
Render a game world on a browser or native surface.
Engine API GameViewnayan-ui/games
Example.tsx
| Name | Type | Default | Details |
|---|---|---|---|
| adaptQuality | boolean | Optional | Whether "auto" judges the device by the frames now (default true). Pass false while what's on screen isn't the game being played (a results card, a menu, a ready screen): their cost says nothing about the game, and a level chosen there would be remembered for the next visit. |
| backdrop | RenderSource | Optional | Static scenery behind `source` (a meadow, sky and hills; a board's backdrop): the renderer draws it once into a cached image with this view's camera and light, and draws it again only when it changes or the camera, light, size or quality do. Each frame then costs one full-screen image instead of the whole scenery, and `source` is always drawn in front of it. It isn't stepped (its velocities and animations stand still): call `backdrop.update(0)` after spawning or changing it. Defaults to `source.backdrop`: a World's still entities (`still: true`, `backdropLayer`). |
| background | ColorInput | Optional | Screen/fog color: CSS or linear 0..1 RGB (alpha ignored). Defaults to NTheme's background, then dark navy. |
| camera | Camera | Optional | Mutate this object (e.g. `camera.eye`) from `onUpdate`; it is read every frame. |
| fog | number | Optional | Distance fog density towards `background` (e.g. 0.02). Default 0 (off). |
| light | Light | Optional | |
| onDrag | ((drag: DragEvent) => void) | Optional | Finger down, moving and up (aiming, dragging pieces, slicing). |
| onError | ((error: Error) => void) | Optional | GPU setup failures and rendering errors. Defaults to console.error. |
| onLongPress | ((x: number, y: number) => void) | Optional | A finger held still for half a second (pick up, show moves). No tap follows. |
| onOverlayTouch | ((phase: OverlayTouchPhase, x: number, y: number) => boolean | void) | Optional | Touches for the overlay, in points in the view. Return true from "start" to claim the touch (a button was hit): its moves and end come here, and the game gets no drag, tap or swipe for it. "cancel" when the system takes the touch. |
| onPinch | ((pinch: PinchEvent) => void) | Optional | Two fingers spreading, pinching or turning (zoom and rotate a board). Ends any drag in progress. |
| onPrimaryAction | (() => void) | Optional | Host primary action for keyboard input, such as Start/Stop or Play Again. |
| onStats | ((stats: GameViewStats) => void) | Optional | Called once a second. |
| onSwipe | ((direction: SwipeDirection) => void) | Optional | A quick flick in one direction (2048, runners, sliding puzzles). |
| onTap | ((x: number, y: number) => void) | Optional | A quick tap, at `x, y` points in the view. `world.pick(x, y)` finds what was tapped. |
| onUpdate | ((dt: number) => void) | Optional | Your game loop, called once per frame before drawing, with the elapsed seconds (capped at 0.1; 0 until the first frame is on screen, so nothing plays out unseen): read input, spawn, move the camera. The world (and `overlay`) is stepped for you right after; call `world.update(dt)` here yourself only to step it at a different point or with a different `dt`. |
| overlay | RenderSource | Optional | A screen-space layer drawn over the scene by the renderer (scoreboards, buttons): usually a second `World`, in points from the view's top-left with y up (so on screen y <= 0) and z toward the viewer within -100..100. Unlit (flat faces show their exact color) and always in front. Stepped each frame like `source`. |
| paused | boolean | Optional | Suspend updates and drawing while keeping the native surface mounted. |
| quality | RenderQualitySetting | Optional | Resolution, anti-aliasing and shadows. "auto" (default) starts at "high", steps down only while the GPU really can't keep up (crisper shadows, then no shadows or anti-aliasing, resolution last) and steps back up once frames are smooth again, so every phone gets the best look it can hold. |
| qualityKey | string | Optional | Remembers the level "auto" settles on under this key (e.g. the game's id) in the engine's durable store, so every later view with the same key, after app restarts too, starts there rather than at "high". |
| source | RenderSource | Required | What to draw (usually a `World`). Changing it restarts the view; never pass a disposed world. |
| style | React.CSSProperties | Optional |
React Native API
| Name | Type | Default | Details |
|---|---|---|---|
| adaptQuality | boolean | Optional | Whether "auto" judges the device by the frames now (default true). Pass false while what's on screen isn't the game being played (a results card, a menu, a ready screen): their cost says nothing about the game, and a level chosen there would be remembered for the next visit. |
| backdrop | RenderSource | Optional | Static scenery behind `source` (a meadow, sky and hills; a board's backdrop): the renderer draws it once into a cached image with this view's camera and light, and draws it again only when it changes or the camera, light, size or quality do. Each frame then costs one full-screen image instead of the whole scenery, and `source` is always drawn in front of it. It isn't stepped (its velocities and animations stand still): call `backdrop.update(0)` after spawning or changing it. Defaults to `source.backdrop`: a World's still entities (`still: true`, `backdropLayer`). |
| background | ColorInput | Optional | Screen/fog color: CSS or linear 0..1 RGB (alpha ignored). Defaults to NTheme's background, then dark navy. |
| camera | Camera | Optional | Mutate this object (e.g. `camera.eye`) from `onUpdate`; it is read every frame. |
| fog | number | Optional | Distance fog density towards `background` (e.g. 0.02). Default 0 (off). |
| light | Light | Optional | |
| onDrag | ((drag: DragEvent) => void) | Optional | Finger down, moving and up (aiming, dragging pieces, slicing). |
| onError | ((error: Error) => void) | Optional | GPU setup failures and rendering errors. Defaults to console.error. |
| onLongPress | ((x: number, y: number) => void) | Optional | A finger held still for half a second (pick up, show moves). No tap follows. |
| onOverlayTouch | ((phase: OverlayTouchPhase, x: number, y: number) => boolean | void) | Optional | Touches for the overlay, in points in the view. Return true from "start" to claim the touch (a button was hit): its moves and end come here, and the game gets no drag, tap or swipe for it. "cancel" when the system takes the touch. |
| onPinch | ((pinch: PinchEvent) => void) | Optional | Two fingers spreading, pinching or turning (zoom and rotate a board). Ends any drag in progress. |
| onPrimaryAction | (() => void) | Optional | Host primary action for keyboard input, such as Start/Stop or Play Again. |
| onStats | ((stats: GameViewStats) => void) | Optional | Called once a second. |
| onSwipe | ((direction: SwipeDirection) => void) | Optional | A quick flick in one direction (2048, runners, sliding puzzles). |
| onTap | ((x: number, y: number) => void) | Optional | A quick tap, at `x, y` points in the view. `world.pick(x, y)` finds what was tapped. |
| onUpdate | ((dt: number) => void) | Optional | Your game loop, called once per frame before drawing, with the elapsed seconds (capped at 0.1; 0 until the first frame is on screen, so nothing plays out unseen): read input, spawn, move the camera. The world (and `overlay`) is stepped for you right after; call `world.update(dt)` here yourself only to step it at a different point or with a different `dt`. |
| overlay | RenderSource | Optional | A screen-space layer drawn over the scene by the renderer (scoreboards, buttons): usually a second `World`, in points from the view's top-left with y up (so on screen y <= 0) and z toward the viewer within -100..100. Unlit (flat faces show their exact color) and always in front. Stepped each frame like `source`. |
| paused | boolean | Optional | Suspend updates and drawing while keeping the native surface mounted. |
| quality | RenderQualitySetting | Optional | Resolution, anti-aliasing and shadows. "auto" (default) starts at "high", steps down only while the GPU really can't keep up (crisper shadows, then no shadows or anti-aliasing, resolution last) and steps back up once frames are smooth again, so every phone gets the best look it can hold. |
| qualityKey | string | Optional | Remembers the level "auto" settles on under this key (e.g. the game's id) in the engine's durable store, so every later view with the same key, after app restarts too, starts there rather than at "high". |
| source | RenderSource | Required | What to draw (usually a `World`). Changing it restarts the view; never pass a disposed world. |
| style | ViewStyle | Optional |