Making a game
Building the HUD
What is drawn over the game: scores, bars, menus, modals and pause screens.
Everything drawn over the game is shown on panels of the ui plugin, from values on the rows the seat is sent. Values only the page keeps, a volume or a mute, are in the store.
Where each piece goes
| Piece | Home |
|---|---|
| The seat's own score, health, ammo | A field of its player row. |
| A value seats share, a round clock | A kind of its own with one actors entry. |
| Volume, mute | A key of the store. |
| Panels, keys, text and button styles | world.ui in the scene file. |
| Every place and word inside a panel | The drawing kind's definition in assets/<game>.json. |
| A picture on the HUD | A catalogue entry with "for": "ui". |
Steps
- Put the value on a row, such as a
scorefield on theplayerprefab. - List
uiin the scene'splugins, andstorewhen a screen sets page-only values. - Write
world.ui: a panel per region, the six keys, and each style. Give a text style's outline,stroke,"join": "round": by default the corners are mitred, and at the sharp points of W, V, A, M and 1 the outline runs out in spikes up to 10 times its width. - Write every place and word on the definitions.
- Draw it in
player.client.ts'stick, for the row that ismine, withui.show(panel, key, make)every frame it should be shown.
"ui": {
"panels": {
"hud": { "anchor": "top-left", "at": [16, 16], "size": [200, 24] },
"pause": { "anchor": "center", "size": [320, 200], "modal": true, "layer": 1, "backdrop": { "color": 0, "alpha": 0.6 } }
},
"keys": { "up": "ArrowUp", "down": "ArrowDown", "left": "ArrowLeft", "right": "ArrowRight", "press": ["Enter", " "], "back": "Escape" },
"styles": { "score": { "fontFamily": "monospace", "fontSize": 20, "fill": 16777215, "stroke": { "color": 0, "width": 3, "join": "round" } } }
}
Screens
- A screen the game puts up, a pause or a game over, is a kind with an
onfield; its look shows it while the row says so. Bind the pause key toworld.ui'sback. - A menu the player opens, an inventory or a map, is a modal panel with a
key; its look shows it whileui.opened(name). The game plays on under it. - The first thing shown on a modal takes the focus.
Starting values for store keys are the store prefab. A volume screen counts whole steps of the definition's steps and divides. A screen where the player sees and rebinds the controls is Building a controls screen.
Checking it
- In
<kind>.client.test.ts, read what is shown off the panel by key:ui.panel('hud').getChildByLabel('score').text. - Open the game's
index.htmlas in Starting a game, change the value in play, and open and leave each screen with keys and the pointer.