marble3 / createHud
Function: createHud()
createHud():
object
Defined in: src/hud.ts:49
Creates a game's screen chrome: plain DOM laid over the canvas, in slots (HUD_SLOTS). BaseGame makes one and start() mounts it, so there is rarely a reason to call this.
Elements are created or updated by id, so calling text('score', …) every frame is the intended use. The HUD lets clicks through to the world, except on its buttons and its dialog.
Returns
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