marble3 / Game
Class: Game
Defined in: src/index.ts:138
A scene viewed through an orbit camera, with no physics and no player: a board game, a model viewer. Add objects to scene, animate them from onFrame, and mount what start() returns.
Extends
Constructors
Constructor
new Game():
Game
Defined in: src/index.ts:73
Returns
Game
Inherited from
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.
Inherited from
disposed
protecteddisposed:boolean=false
Defined in: src/index.ts:57
Inherited from
hud
hud:
object
Defined in: src/index.ts:51
root
root:
HTMLDivElement
banner()
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
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
Inherited from
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.
Inherited from
onFrame?
optionalonFrame?: (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
Inherited from
onResizeHook?
optionalonResizeHook?: (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
Inherited from
onWindowResize?
protectedoptionalonWindowResize?: () =>void
Defined in: src/index.ts:56
Returns
void
Inherited from
orbit
orbit:
OrbitControls
Defined in: src/index.ts:53
Orbit controls on camera. FPS.start() disables them.
Inherited from
renderer
renderer:
WebGLRenderer
Defined in: src/index.ts:40
Inherited from
renderFrame?
optionalrenderFrame?: (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
Inherited from
scene
scene:
Scene
Defined in: src/index.ts:54
Inherited from
stats
stats:
Stats
Defined in: src/index.ts:48
Frame-rate meter, updated every frame. Append stats.dom to show it.
Inherited from
viewCamera?
optionalviewCamera?: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.
Inherited from
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
Inherited from
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
Inherited from
start()
start(
x,y,z):HTMLElement
Defined in: src/index.ts:143
Starts rendering and returns the element to mount (canvas and HUD). The camera orbits the point (x, 0, z), starting 25 units from it along −x at height y.
Parameters
x
number
y
number
z
number
Returns
HTMLElement