logo

Babylon.js Market

SpaceShooterFX

fx · space-combat-sim

SpaceShooterFX

1
Unlock

Install with the CLI:

bjs download SpaceShooterFX

SpaceShooterFX

Turns the space shooter's death and launch events into light on the screen.

What it does

SpaceShooterFX is the listener for four events that the combat components have always emitted and nothing has ever drawn. Put one on the world entity and kills, missile hits, launches and your own death all produce particle bursts.

An explosion is two layers, and it needs both. A fast white-hot burst of 3000 particles, large and slow enough to stay legible at the 200–500 unit range you normally see a kill from; then 700 slow orange embers that drift outward and fade. The burst alone reads as a flashbulb — the embers are what read as burning.

The colours exceed 1.0 on purpose. They are HDR values feeding the bloom pass, so a red channel of 3.4 is what makes the core of a blast bleed white while its edges stay orange.

EventEffect
spaceshooter.explosionwhite-hot burst + slow embers
spaceshooter.player.blownapartthe same, scaled by playerDeathScale
spaceshooter.missile.fireda brief blue-white exhaust burn
spaceshooter.missile.explodeda detonation at the impact point

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 SpaceShooterFX
    bjs download SpaceShooterFX

    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": {
      "SpaceShooterFX": { "density": 1, "scale": 1, "playerDeathScale": 2 }
    }
  }
}

Props

  • density (number, default 1) — multiplier on every particle count. The one knob worth reaching for on a weak GPU: 0.25 keeps the shape of each effect and quarters the fill cost.
  • scale (number, default 1) — multiplier on every particle size. Scale up for a bigger ship.
  • playerDeathScale (number, default 2) — extra count multiplier on your own death, which is a bigger event than a fighter's.

Events

  • listens for spaceshooter.explosion, spaceshooter.player.blownapart, spaceshooter.missile.exploded, spaceshooter.missile.fired.
  • emits nothing.

Dependencies

None. It reacts to whatever emits those names — SpaceShooterHealth's kill path, Missile, MissileLauncher.

Notes

  • The sprite is uploaded lazily, on the first effect. A scene that never kills anything never pays for the texture, and the cache dedupes every call after that.
  • Each burst gets a fresh position array. The spec holds the array rather than copying it, so reusing one scratch vector meant the next kill in a firefight dragged the previous explosion across the sky. These are rare one-shot events already minting thousands of particles; one three-element array is not the cost to optimise.
  • An event with no usable position is dropped rather than flashing at the origin — a burst in the wrong place is worse than none.
  • Unpauseable, so a death still flashes if the host pauses the world on death. That pause is exactly the linger RoundReset holds so the explosion can be seen.
  • Bursts auto-dispose, so there is no per-frame work and nothing to clean up.

More like this

Missile
MissileLauncher
SpaceShooterBullet
SpaceShooterHealth
Asteroid
AsteroidField
CameraState6DOF
ChaseCamera6DOF
ChaseCameraTarget
FlightIntent
FreighterCar
FreighterChain
FreighterHead
GameConfig
LensFlare
NebulaSky
OilBlob
PlayerFlightInput
Renderable
RoundReset
ShipDamageFX
ShipFlight
SpaceDust
SpaceShooterHUD
SpaceShooterScore
Transform6DOF
Velocity6DOF
WaveDirector
Waypoint
WaypointTrack
WorldOriginAnchor

Was this page helpful?

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

↑↓ NavigateEnter SelectEsc CloseCtrl+K Open Search