Entities
Gamehoster.Entities is a Map of the
entity views you can see, keyed by netId. Rocks, bullets and every other
non-player object live here. Pick one kind with Gamehoster.Entities.ofType(type).
The map
| Member | Holds |
|---|---|
Gamehoster.Entities.get(netId) | the view for that netId. |
Gamehoster.Entities.ofType(type) | the views of one entity type (e.g. 'rock'). |
Gamehoster.Entities.values() | iterate every entity view. |
Gamehoster.Entities.size | how many entities are in view. |
An entity view
| Member | Holds |
|---|---|
| fields | each entity schema field, eased for this frame, at the top level. |
.current | the newest authoritative sample, un-interpolated. |
.prev | the previous sample. |
.data | the view's front-end bag, kept for the entity's whole visible life. |
.id | a stable id for the entity's whole visible life. |
.type | the entity's type name. |
for (var rock of Gamehoster.Entities.ofType('rock')) drawRock(rock, Gamehoster.Frame.tick)
for (var shot of Gamehoster.Entities.ofType('bullet')) drawShot(shot, Gamehoster.Frame.tick)
Ballistic entities
A ballistic entity, a rock or a bullet, carries only its start point, its velocity and its spawn tick. It
needs no per-tick sample stream: the renderer computes its position from those constants and the current
Gamehoster.Frame.tick.
var t = Gamehoster.Frame.tick - rock.spawnTick
var x = rock.x0 + rock.vx * t
var y = rock.y0 + rock.vy * t
drawAt(x, y, rock.spin * t)
The entity bodies
Three client-only bodies sit beside an entity type's schema. Each is optional.
| Body | When it runs | For |
|---|---|---|
gamehoster-entity-enter.js |
an entity appears | Seed that view's .data bag. |
gamehoster-entity-smooth.js |
each frame | Shape how the view eases between authoritative samples. |
gamehoster-entity-exit.js |
an entity leaves your view | Tidy up anything the bag held, or start a fade-out. |