Floating text and bars
Numbers that float up from a hit, health bars and plates over units, pings on the map, and elements of your own pinned to a unit. The full guide is Pings, floating words and the unit HUD; this page is the short version.
Quick start
import { presetFloats } from '@v12-engine/client'
export const view: GameView = {
units: { looks: {} },
hud: {
// damage, heal, crit, xp… with the client's looks; damage in red
floats: presetFloats(['damage', 'heal', 'crit'], { damage: { style: { color: [1, 0.3, 0.3] } } })
}
}Hits now float red numbers, heals and crits the client's way. Nothing floats for a kind you don't list.
Common tasks
Float words from code
client.floats.show('Rally!', { on: id })
const counter = client.floats.show(def, { on: id, amount: 50 })
counter.update(55) // count it up
counter.end()
client.floats.set('damage', null) // stop floating damage while the game playsDecide per hit
floats: { damage: ({ amount }) => (amount > 100 ? big : null) } // null floats nothingChange a unit's plate
looks: { knight: { ...knight, unitHud: { plates: [{ when: { relation: ['self', 'ally'] }, show: 'hurt', items: [{ bar: 'health', ghost: { seconds: 0.5 } }] }] } } }
client.unitHud.set(id, def) // one unit, while the game runs
client.unitHud.look.within = 60 // plates within 60 cells of the cameraSee also How do I change a unit plate.
Send a ping
pings: { kinds: presetPings() } // in the view
client.pings.send(kind, point)
client.minimapPing(x, z, color)The player pings with Alt+left click, or holds Ctrl+left for the ping wheel. See How do I add a ping.
Pin an element over a unit
const pin = client.attach(label, { entity: id }, { offset: { y: -4 } }) // gone with the unit, hidden where it isn't seen
client.attach(flag, { x: 40, z: 22 }, { anchor: 'center', hideWhenUnseen: true })
pin.move({ x: 41, z: 22 })
pin.remove()A renderer of the game's puts its own elements in kit.root, the game's element.
Add a layer between the scene and the HUD
const remove = client.addLayer(myCanvas, { over: 'scene' }) // or { under: 'hud' }A layer lets the pointer through unless it sets pointer-events: auto.
Change bars and rings in code
bars(entity) hides, shows, labels, colours and adds bars; ring(entity) changes the selection ring.
Editor
- Open the Unit HUD panel to build plates by eye, or the Words panel for floating text.
- Pick a unit type or a kind of float.
- Change the widgets, colours and motion; the map shows it live.
- Save: plates go to
hud.json, floats tofloats.json, pings topings.json(the Look panel's Pings fold), laid over your code.
Reference
Float kinds
damage, damageTaken, crit, heal, miss, xp, mana, bounty, levelUp, buff, deny, resource, sleep, or a game event's id. Damage and healing show on every screen that sees the unit; xp, mana and your pools (resource, emitted as resourceChanged) only to the owner and allies.
A float def
| Part | What |
|---|---|
| words | text or a function (({ amount }) => \-${amount}`); braces fill in: '-{amount}', 'Level {amount}'` |
| style | font, weight, size, colour, outline, box, icon; scaleBy: { small, big, most } sizes by amount |
| motion | rise, drift, arc, pop, bounce, shake, scaleBy, custom, each with an ease of kit.eases |
| life | how long it lasts and how it fades; where on the unit it starts |
merge | hits of one key within a window become one number (summed, counted or the largest), counted up |
most, within | caps to keep a big fight cheap |
render | the overlay canvas, page elements ('gui', the old name of a text drawn with the scene, is the canvas's), 'world' (a camera-facing plane, hidden behind trees, FLOAT_WORLD_PIXELS), or your own drawing |
presetFloats() is a def for every kind; presetFloats(kinds, overrides) picks some.
Plates (UnitHudDef)
A plate is widgets laid out over the head: bar (ghost, smooth, segments, label, direction), text, badge, icon, abilities (cooldowns; own for the owner and allies), buffs (time left swept), portrait, ring, stack, row, column, space, and your own dom, gui, draw. Any value can be a function of the unit; each shows always, when hurt, selected, on hover, or by a function.
| Field | What |
|---|---|
plates | the first whose when holds (relation: self, ally, enemy, neutral; selected, hovered, hurt, asleep, constructing, or your of(entity, context)) |
within, far | plates within so many cells of the camera, and the far plate past it |
fixedSize | false: sized by the camera's distance (sizeAt) |
above | height over the head |
fade | seconds in and out (0.15) |
audience, for | who sees it: owner, allies, enemies, everyone |
render | canvas (default, cheapest), dom (styled by your CSS: .vg-hud, .vg-hud-w, data-bar, --fill), gui |
remembered | for a building under fog: 'plate' or 'far', greyed by grey |
Set per type (UnitLook.unitHud), for the game (GameView.units.hud.def), or draw all plates yourself (GameView.units.hud.system(kit)). GameView.units.hud.look sets the defaults. In code: client.unitHud.set(id, def), of(id), plate(id), defs.set(type, def), look.
What another player's plate can show is what the simulation sends: the rules' hud settings (buffs, abilities, a hero's xp) and components with replicate, read with hudData(entity, component). See Multiplayer.
Pings (GameView.pings.kinds)
Each kind has a label, mark or picture, colour, sound, effect, seconds, audience, wheel slot, cooldown, and how its mark is drawn. presetPings() gives the classic set; wheel: { hidden: true } keeps a kind off the wheel. Order marks take their colours from pings.
Marks on the ground (GameView.fx.marks)
The rings of an impact and of a hero levelling up, false for none, or your own drawing; reveal for revealed areas; aim for the aim indicator's colour.
Layers, bottom to top (client.layers)
scene (the 3D canvas), bars (bars, floating words, rings), world (what attach and DOM plates use), the HUD, then overlays (tooltips, toasts, dialogs, menus). All live in the game's element (client.layers.root).