# @ferret/game: API

`createGame`: wires platform, Babylon engine, scene, world, display, input and physics into a running game.

3 exports. Generated from the source (`packages/game/src`), so it matches the code.

## Functions

### createGame

*function* · `packages/game/src/index.ts:50`

```ts
function createGame(opts: GameOptions): Game
```

Wire the usual pieces for a game: platform (OS Beroun or browser), Babylon engine, scene, world, display (render scale,
quality, FOV), input and physics. The game then adds its own services, levels and entities and calls `start()`.
On OS Beroun the engine is made the way /lib/beroun-3d.js does it (the console's 640x480 at density 1, no antialiasing).

## Interfaces

### Game

*interface* · `packages/game/src/index.ts:24`

```ts
interface Game
```

- `engine: BABYLON.AbstractEngine`
- `scene: BABYLON.Scene`
- `world: World`
- `host: SceneHost` — the scene host: second worlds on the shared engine (a game's interlude during a travel)
- `platform: FerretPlatform`
- `display: Display`
- `input: InputService`
- `physics: PhysicsService`
- `touch?: TouchControls`
- `xr?: XrService` — the VR session service, once loaded: only when `xr` was set and the browser has WebXR (the package is fetched then, not before)
- `xrReady: Promise<XrService | undefined>` — resolves when the VR service is added (or at once when it is not wanted)
- `start(): void` — Run the render loop (and with it the fixed-step simulation).
- `stop(): void`
- `dispose(): void`

### GameOptions

*interface* · `packages/game/src/index.ts:7`

```ts
interface GameOptions
```

- `canvas: HTMLCanvasElement`
- `input: Omit<InputOptions, 'defaultKind'> & { defaultKind?: InputOptions['defaultKind'] }`
- `platform?: FerretPlatform`
- `storageKey?: string` — key for browser storage (one per game)
- `physicsLayers?: string[]`
- `tier?: QualityTier`
- `touchControls?: boolean` — Touch controls on phones and tablets (default true)
- `clearColor?: [number, number, number]`
- `fov?: { baseVertical?: number; minHorizontal?: number }` — the camera's field of view: the vertical one (radians) at wide aspects, and the horizontal one it never falls below (a game that matches another engine's 90 degrees passes both)
- `xr?: XrOptions` — VR through WebXR: `{ enabled: true }` adds the `xr` service where the browser has WebXR; elsewhere (OS Beroun) nothing is added

