logo

Babylon.js Market

RoundReset

gameplay

RoundReset

1
Unlock

Install with the CLI:

bjs download RoundReset

RoundReset

Ends the round on a death, holds still long enough to see it, then asks for a rebuild.

What it does

RoundReset is the round lifecycle: death → linger → start over. Put one on the world entity and name the events that mean "the round is over" in its on list. When one arrives the component flips to phase lingering, arms remaining from lingerSeconds, and emits round.reset.pending. When the clock runs out it emits round.reset.request.

The linger is what the component is for. Resetting the instant a player dies throws away the only feedback that explains the death — the explosion, the tumbling wreck, the asteroid still sitting where they flew into it. Three seconds is long enough to read the wreck and short enough not to feel like a punishment.

It does not rebuild the scene itself, because it can't: reloading a scene means owning the canvas, the renderer and the component registry, all of which belong to whatever built the game. So the last step is a request, and the host answers it:

TypeScript
game.eventBus.on(RoundResetEvents.REQUEST, () => {
  teardown(game);
  game = await buildGame(entry);
});

A host that ignores the request gets a game that lingers forever, which is why the event is imperative and named for the action.

Use it in a scene

A scene is just data — a list of entities, each with its components. At startup the SceneLoader turns this JSON into a live world; edit the file and reload to rebuild it.

Build it from scratch with the bjs CLI:

  1. 1Scaffold a project
    npm create @babylonjsmarket/arcade@latest my-game

    World, renderer, and dev server — ready to run.

  2. 2Install dependencies
    cd my-game && npm install
  3. 3Add RoundReset
    bjs download RoundReset

    Copies its source into src/ so the scene resolves.

    First time? Run bjs login once.

  4. 4Paste the scene into src/scenes/arcade-room.ts and run
    npm run dev

    SceneLoader builds the world from the JSON; reload to rebuild.

JSON
{
  "World": {
    "tags": ["world"],
    "components": {
      "RoundReset": {
        "on": ["spaceshooter.player.killed", "spaceshooter.freighter.killed"],
        "lingerSeconds": 3
      }
    }
  }
}

Props

  • lingerSeconds (number, default 3) — seconds the wreck stays on screen before the request goes out.
  • on (string[], default ["game.player.died"]) — events that end the round. Point it at whatever your genre already emits; a space shooter uses spaceshooter.player.killed.
  • phase ('running' | 'lingering', default 'running') — live phase. Serialised, so a save taken mid-death restores mid-death.
  • remaining (number, default 0) — seconds left in the linger. Meaningless while running.

Events

  • emits round.reset.pending { lingerSeconds } — the round just ended and the countdown started. A HUD draws its death overlay off this.
  • emits round.reset.request {} — the linger elapsed; rebuild now.
  • listens for every name in on. The canonical cross-game signal is game.player.died; a subgenre with its own name for the same fact points on at it rather than emitting a duplicate.

Dependencies

None.

Notes

  • Repeat deaths during the linger are ignored. Debris keeps landing hits after the player is gone, and re-arming the clock on each one is how a 3-second linger becomes an infinite one.
  • The countdown is unpauseable. The linger is chrome around a stopped game, so a host that pauses the world on death would otherwise freeze the very clock that un-freezes it.
  • lingerSeconds: 0 still gives the host one frame before the request — the death frame renders.
  • The phase flips back to running before the request goes out, so the component reads as a fresh round even if it survives a synchronous rebuild.

More like this

SpaceShooterHUD
AiPilot
Animation
ArcCamera
Asteroid
BallPossession
BallReset
Bullet
CameraFollow
DirectionalLight
Enemy
EnemySpawner
EnvironmentTexture
FreighterCar
FreighterChain
FreighterHead
GameConfig
Goal
Health
HemisphericLight
Jump
KeyboardInput
KeyboardMover
Lifetime
LineOfSight
MachineGun
Mesh
MeshPrimitive
Missile
MissileLauncher
MissionDirector
MouseInput
Movement
Obstacle
ObstacleField
OilBlob
Parts
Physics
PlayerInput
PlayerWalkAnimator
RespawnTimer
Score
Scoreboard
Shadow
ShipLoadout
SkeletonAnimator
SoccerDirector
SpaceShooterBullet
SpaceShooterFX
SpaceShooterHealth
SpaceShooterScore
WaveDirector
Waypoint
WaypointTrack

Was this page helpful?

We read every note — tell us what's working and what isn't.

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search