Skip to content

marble3 / BaseGame

Class: BaseGame ​

Defined in: src/index.ts:39

What Game and FPS share: a WebGL renderer sized to the window, a scene, an orbit camera, a HUD and a layer for in-world HTML labels. Use one of the two subclasses. Their start() returns the element to mount, and dispose() (or disposeGame) must be called when it is unmounted, or the render loop keeps running.

Extended by ​

Constructors ​

Constructor ​

new BaseGame(): BaseGame

Defined in: src/index.ts:73

Returns ​

BaseGame

Properties ​

camera ​

camera: PerspectiveCamera

Defined in: src/index.ts:50

The orbit camera a Game renders through. An FPS renders through its player's camera instead.


disposed ​

protected disposed: boolean = false

Defined in: src/index.ts:57


hud ​

hud: object

Defined in: src/index.ts:51

root ​

root: HTMLDivElement

banner(text): void

A card in the middle of the screen, for a line or a few. One at a time; an empty string removes it. It does not take clicks.

Parameters ​
text ​

string

Returns ​

void

bar() ​

bar(id, __namedParameters): void

A progress bar. The fill is clamped between empty and full.

Parameters ​
id ​

string

__namedParameters ​

HudBar

Returns ​

void

button() ​

button(id, label, onClick, slotName?): void

A button. Declaring an id again updates its label and replaces its handler.

Parameters ​
id ​

string

label ​

string

onClick ​

() => void

slotName? ​

"center" | "bottom" | "top" | "top-left" | "above-center" | "below-center" | "rail"

Returns ​

void

dialog() ​

dialog(content): void

A card over a dimmed world that takes the pointer, so no click reaches the world behind. One at a time; null closes it. See HudDialog.

Parameters ​
content ​

HudDialog | null

Returns ​

void

dispose() ​

dispose(): void

Takes the HUD off the page.

Returns ​

void

hint() ​

hint(text, slotName?): void

A blinking prompt, such as "press any key". One at a time; an empty string removes it.

Parameters ​
text ​

string

slotName? ​

"center" | "bottom" | "top" | "top-left" | "above-center" | "below-center" | "rail"

Returns ​

void

mount() ​

mount(slotName, el): void

Puts an element of your own in a slot. One per slot; null removes it.

Parameters ​
slotName ​

"center" | "bottom" | "top" | "top-left" | "above-center" | "below-center" | "rail"

el ​

HTMLElement | null

Returns ​

void

text() ​

text(id, text, slotName?): void

A line of white text; newlines are kept.

Parameters ​
id ​

string

text ​

string

slotName? ​

"center" | "bottom" | "top" | "top-left" | "above-center" | "below-center" | "rail"

Returns ​

void


labelRenderer ​

labelRenderer: CSS2DRenderer

Defined in: src/index.ts:46

Draws in-world HTML (SpeechBubble) over the canvas. FPS renders it every frame; Game does not, so a Game scene that uses bubbles must call labelRenderer.render(scene, camera) from onFrame.


onFrame? ​

optional onFrame?: (delta) => void

Defined in: src/index.ts:71

Game only. Called every frame with the seconds since the last one.

Parameters ​

delta ​

number

Returns ​

void


onResizeHook? ​

optional onResizeHook?: (width, height) => void

Defined in: src/index.ts:69

FPS only. Called after the engine has resized the renderer, the labels and the cameras.

Parameters ​

width ​

number

height ​

number

Returns ​

void


onWindowResize? ​

protected optional onWindowResize?: () => void

Defined in: src/index.ts:56

Returns ​

void


orbit ​

orbit: OrbitControls

Defined in: src/index.ts:53

Orbit controls on camera. FPS.start() disables them.


renderer ​

renderer: WebGLRenderer

Defined in: src/index.ts:40


renderFrame? ​

optional renderFrame?: (scene, camera) => void

Defined in: src/index.ts:62

FPS only. Draws the frame in place of renderer.render(scene, camera), to route it through a post-processing composer.

Parameters ​

scene ​

Scene

camera ​

Camera

Returns ​

void


scene ​

scene: Scene

Defined in: src/index.ts:54


stats ​

stats: Stats

Defined in: src/index.ts:48

Frame-rate meter, updated every frame. Append stats.dom to show it.


viewCamera? ​

optional viewCamera?: Camera

Defined in: src/index.ts:67

FPS only. A fixed camera the frame and the in-world labels are drawn through instead of the player's, for a world watched from outside rather than played from inside.

Methods ​

createContainer() ​

createContainer(): HTMLElement

Defined in: src/index.ts:105

Builds the element start() returns: the canvas and the label layer, tagged data-game-root.

Returns ​

HTMLElement


dispose() ​

dispose(): void

Defined in: src/index.ts:120

Stops the render loop and releases the renderer, the controls, the HUD and the resize listener. Idempotent.

Returns ​

void