Skip to content
  • Android
  • iOS
  • Web

Game View

Render a game world on a browser or native surface.

Engine API GameViewnayan-ui/games

Live examples

Example.tsx

Preparing preview…

Attributes

GameView attributes
NameTypeDefaultDetails
adaptQualitybooleanOptionalWhether "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.
backdropRenderSourceOptionalStatic 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`).
backgroundColorInputOptionalScreen/fog color: CSS or linear 0..1 RGB (alpha ignored). Defaults to NTheme's background, then dark navy.
cameraCameraOptionalMutate this object (e.g. `camera.eye`) from `onUpdate`; it is read every frame.
fognumberOptionalDistance fog density towards `background` (e.g. 0.02). Default 0 (off).
lightLightOptional
onDrag((drag: DragEvent) => void)OptionalFinger down, moving and up (aiming, dragging pieces, slicing).
onError((error: Error) => void)OptionalGPU setup failures and rendering errors. Defaults to console.error.
onLongPress((x: number, y: number) => void)OptionalA finger held still for half a second (pick up, show moves). No tap follows.
onOverlayTouch((phase: OverlayTouchPhase, x: number, y: number) => boolean | void)OptionalTouches 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)OptionalTwo fingers spreading, pinching or turning (zoom and rotate a board). Ends any drag in progress.
onPrimaryAction(() => void)OptionalHost primary action for keyboard input, such as Start/Stop or Play Again.
onStats((stats: GameViewStats) => void)OptionalCalled once a second.
onSwipe((direction: SwipeDirection) => void)OptionalA quick flick in one direction (2048, runners, sliding puzzles).
onTap((x: number, y: number) => void)OptionalA quick tap, at `x, y` points in the view. `world.pick(x, y)` finds what was tapped.
onUpdate((dt: number) => void)OptionalYour 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`.
overlayRenderSourceOptionalA 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`.
pausedbooleanOptionalSuspend updates and drawing while keeping the native surface mounted.
qualityRenderQualitySettingOptionalResolution, 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.
qualityKeystringOptionalRemembers 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".
sourceRenderSourceRequiredWhat to draw (usually a `World`). Changing it restarts the view; never pass a disposed world.
styleReact.CSSPropertiesOptional
React Native API

React Native attributes

GameView react native attributes
NameTypeDefaultDetails
adaptQualitybooleanOptionalWhether "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.
backdropRenderSourceOptionalStatic 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`).
backgroundColorInputOptionalScreen/fog color: CSS or linear 0..1 RGB (alpha ignored). Defaults to NTheme's background, then dark navy.
cameraCameraOptionalMutate this object (e.g. `camera.eye`) from `onUpdate`; it is read every frame.
fognumberOptionalDistance fog density towards `background` (e.g. 0.02). Default 0 (off).
lightLightOptional
onDrag((drag: DragEvent) => void)OptionalFinger down, moving and up (aiming, dragging pieces, slicing).
onError((error: Error) => void)OptionalGPU setup failures and rendering errors. Defaults to console.error.
onLongPress((x: number, y: number) => void)OptionalA finger held still for half a second (pick up, show moves). No tap follows.
onOverlayTouch((phase: OverlayTouchPhase, x: number, y: number) => boolean | void)OptionalTouches 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)OptionalTwo fingers spreading, pinching or turning (zoom and rotate a board). Ends any drag in progress.
onPrimaryAction(() => void)OptionalHost primary action for keyboard input, such as Start/Stop or Play Again.
onStats((stats: GameViewStats) => void)OptionalCalled once a second.
onSwipe((direction: SwipeDirection) => void)OptionalA quick flick in one direction (2048, runners, sliding puzzles).
onTap((x: number, y: number) => void)OptionalA quick tap, at `x, y` points in the view. `world.pick(x, y)` finds what was tapped.
onUpdate((dt: number) => void)OptionalYour 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`.
overlayRenderSourceOptionalA 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`.
pausedbooleanOptionalSuspend updates and drawing while keeping the native surface mounted.
qualityRenderQualitySettingOptionalResolution, 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.
qualityKeystringOptionalRemembers 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".
sourceRenderSourceRequiredWhat to draw (usually a `World`). Changing it restarts the view; never pass a disposed world.
styleViewStyleOptional
Game Runtime module

Tags