marble3 / FPS
Class: FPS
Defined in: src/index.ts:186
A world with physics, played from inside: a Bullet world stepped every frame, entities added with add(), and a loading screen that keeps the world paused until its assets have arrived.
Construct it before loading any asset (the loading screen counts loads from that moment), add the entities, then mount what start() returns.
Extends
Constructors
Constructor
new FPS():
FPS
Defined in: src/index.ts:215
Returns
FPS
Overrides
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
entities
entities:
object={}
Defined in: src/index.ts:207
Every entity in the world, by id.
Index Signature
[id: string]: Player | PhysicEntity | GraphicEntity
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
maxStepDelta
maxStepDelta:
number=0.1
Defined in: src/index.ts:199
The longest frame time, in seconds, handed to the physics, so a stall is not replayed in one frame.
maxSubSteps
maxSubSteps:
number=2
Defined in: src/index.ts:197
The most physics steps run in one frame. Below about 30 fps the simulation falls behind real time (slow motion) instead of spending ever more of each frame catching up: at 10, a slow frame asked for more steps, which made the next frame slower still, until the page froze.
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
paused
paused:
boolean=false
Defined in: src/index.ts:204
While true, physics and entity updates are skipped and the scene still renders. The loading screen holds it true until the world's assets have settled.
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
timeStep
timeStep:
number
Defined in: src/index.ts:191
The fixed physics step, in seconds.
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
world
world:
btDiscreteDynamicsWorld
Defined in: src/index.ts:188
The Bullet world. Entities put their bodies in it through add().
Methods
add()
add(
entity):void
Defined in: src/index.ts:224
Adds an entity to the scene and, when it owns physics bodies, to the world.
Parameters
entity
Returns
void
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:240
Stops the loop, then removes and disposes every entity, then frees the physics world. Idempotent.
Returns
void
Overrides
manageCollisions()
manageCollisions():
void
Defined in: src/index.ts:356
Runs the registered collision callbacks for the current contacts. The loop calls it after each physics step.
Returns
void
pause()
pause():
void
Defined in: src/index.ts:250
Freezes physics and entity updates. The scene keeps rendering.
Returns
void
registerCollisionCallback()
registerCollisionCallback(
entity1,entity2,callback):void
Defined in: src/index.ts:350
Calls callback on every frame in which the two entities touch. One callback per pair: registering the pair again, in either order, replaces it. The arguments arrive in Bullet's order, which may not be the order registered.
Parameters
entity1
Player | CharacterEntity | PhysicEntity
entity2
Player | CharacterEntity | PhysicEntity
callback
(entity1, entity2) => void
Returns
void
remove()
remove(
entity):void
Defined in: src/index.ts:231
Takes an entity out of the world and disposes it. It cannot be added again.
Parameters
entity
Returns
void
resume()
resume():
void
Defined in: src/index.ts:254
Returns
void
start()
Call Signature
start(
player):HTMLElement
Defined in: src/index.ts:265
Starts the loop and returns the element to mount (canvas, HUD and loading screen). Pass the Player to see through its camera, or { camera } for a world nobody walks in.
Entities are updated once before the first physics step, so terrain added before start() is under the player when the world begins.
Parameters
player
Returns
HTMLElement
Call Signature
start(
view):HTMLElement
Defined in: src/index.ts:266
Starts the loop and returns the element to mount (canvas, HUD and loading screen). Pass the Player to see through its camera, or { camera } for a world nobody walks in.
Entities are updated once before the first physics step, so terrain added before start() is under the player when the world begins.
Parameters
view
camera
PerspectiveCamera
Returns
HTMLElement
update()
update(
delta?):void
Defined in: src/index.ts:336
Calls update(delta, this) on every entity. The loop does it each frame while not paused.
Parameters
delta?
number = 0
Returns
void