Skip to content

Show an effect ​

Fire, explosions, smoke, sparks, beams: each is an effect you name in the view and play by name, from the rules (every player sees it) or from the client (this screen only). The client ships 38 ready-made ones.

Quick start ​

Take the ready-made effects you want into the view:

ts
import { presetFx, type GameView } from '@v12-engine/client'

export const view: GameView = {
	units: { looks: {} },
	fx: { defs: presetFx(['explosion', 'fire', 'smoke', 'heal']) }
}

Then play one from the rules, so every player who sees the spot sees it at the same moment (and in replays):

ts
import type { Entity, World } from '@v12-engine/engine'

declare const world: World
declare const mine: Entity

world.fx('explosion', { at: { x: mine.pos.x, z: mine.pos.z }, params: { size: 2 } })

A blast twice the made size, with its flash, fireball, sparks, smoke, shake and scorch mark. The client plays no effect the view doesn't have.

Common tasks ​

Play one on a unit ​

on follows the unit; point names a point of its model.

ts
import type { Entity, World } from '@v12-engine/engine'

declare const world: World
declare const house: Entity

const id = world.fx('fire', { on: house, point: 'roof' })
world.stopFx(id, { fade: 1 })

Play one on this screen only ​

From client code (a menu, a cinematic, a button), client.fx.play returns a handle you can tune and stop.

ts
import type { GameClientApi } from '@v12-engine/client'

declare const client: GameClientApi
declare const unitId: number

const burn = client.fx.play('fire', { on: unitId, point: 'roof', params: { size: 2 } })
burn.set({ size: 0.5 }) // knobs change while it plays
burn.stop({ mode: 'fade', fade: 1 })
await burn.done

Change a ready-made effect ​

Give it knobs of your own, or make a new one from it with fx.extend.

ts
import { fx, presetFx, type GameView } from '@v12-engine/client'

export const view: GameView = {
	units: { looks: {} },
	fx: {
		defs: {
			...presetFx(['fire', 'smoke'], { fire: { color: '#ffb050' } }),
			'frost.fire': fx.extend('fire', { color: '#9fe8ff', tint: '#2a7fff', smoke: false })
		}
	}
}

Show it only to some players, over the fog ​

ts
import type { Entity, World } from '@v12-engine/engine'

declare const world: World
declare const shrine: Entity

world.fx('beam', { at: shrine.pos, to: [1, 2], overFog: true })

Draw a beam between two units ​

Effects drawn between two points are played with their other end (toward). linkFx() adds three: ray (a pulsing beam), tether (a sagging rope), chain (a crackling bolt).

ts
import { linkFx, presetFx, type GameView } from '@v12-engine/client'
import type { Entity, World } from '@v12-engine/engine'

export const view: GameView = { units: { looks: {} }, fx: { defs: { ...presetFx(), ...linkFx() } } }

declare const world: World
declare const caster: Entity
declare const target: Entity
world.fx('ray', { on: caster, toward: target })

Play an effect on a game event ​

Declare it in the view by event id: an effect where the event says (x, z, or entity), a sound, a shake.

ts
on: {
	'mine.exploded': { fx: 'explosion', params: (event) => ({ size: event.power }), sound: 'boom', shake: 0.6 },
	'wave.started': (event, client) => client.camera.lookAt(event.gate)
}

Place an effect on the map ​

A campfire, a chimney's smoke, a waterfall's mist that play for as long as the map does: use the editor's effect tool (see below). They're saved in the map's file (MapEnvironment.fx), drawn for every player, and never seen by the rules. In a game, client.mapFx.named('campfire') gives what plays of one.

Give an ability or a shot an effect ​

See Ability visuals. An attack's shot carries one with ShotDef.fx and lands with ShotDef.impact.

Editor ​

Try any effect in a game:

  1. Open the debug panel (🐞, or Alt+Shift+D) and find Effects.
  2. Type a name or a word ("sparks", "magic") and pick one.
  3. Play it on the selected units, where the camera looks, or where I click (a projectile like fireball is thrown there from the first selected unit). Shift keeps clicking; Esc stops.
  4. Stop all stops what you played. It plays on this screen only.

Place one on the map:

  1. Press X (the effect tool, sparkles on the strip) and click the map.
  2. Drag to move, [ and ] to turn; the handles move, turn and resize it.
  3. In the Inspector, pick its effect, knobs, when (always, at night, by day, between two hours) and from which quality it plays.

Tune or make one: the Effects panel, see Make your own effect.

Reference ​

Playing options ​

OptionRules world.fxClient fx.playWhat it does
at✓✓A place { x, z } (or with y)
on✓✓An entity to follow; ends with it unless stay
point✓✓A point of its model (roof, weapon)
params✓✓Knobs
toward✓The other end of a beam: an entity or a place
to✓Only these players
overFog✓✓Shown over the fog of war
seed✓Same random choices every time

world.fx returns an id for world.stopFx(id, { fade }). The client's FxHandle: set(params), stop({ mode, fade }) (at-once, fade, or finish, the default: what's alive ends by itself), hold(true | false) (freeze in place), move(to), done, alive, length, particles.

Things worth knowing ​

  • An effect is hidden where the player can't see (the fog), and while the entity it is on isn't seen. Its sound isn't heard there either.
  • Effects from the rules go to the screens of the players who see the spot or know the entity. Their random choices use a seed shared by every screen.
  • Effects aren't in the world's state, a save, or sent to a player who joins later. What lasts shows through what the world keeps (a building's damaged look, a map's own effects).
  • In code: client.fx.define(name, def) defines one by name, GameView.fx.for decides one by name before those declared, client.fx.play({ parts: [...] }) plays one unnamed, client.fx.stats() says what's alive.
  • client.debugTools.playFx(name, 'selected' | 'focus' | { x, z }, params) plays from code what the debug panel plays. GameView.hud.debug.hide: ['effects'] hides that section.
  • A map's effects in code: editor.doc.look.addFx(at, { fx }), look.setFx(id, change), look.removeFx(ids); a map's lasting marks (a scorch, a rune) are decals, not effects.

Ready-made effects ​

presetFx(names?, params?) takes them into the view (PRESET_FX). They use the pictures of @v12-engine/assets' fx group (Kenney's Particle Pack, CC0) where the game has the package, and pictures made in the page where it hasn't (ParticleDef.fallback). Each picture is at its default knobs, by day.

Fire ​

EffectIts knobs
firefire: flames, embers, a flickering light, smoke over itsize (1); color ("#ff9a2e"): the flames' heart; tint ("#e8360c"): their tips; rate (60); light (1.4): 0 for none; smoke ({"darkness":0.55}): its knobs, or false; embers (true)
torchtorch: a small flickering flame with its lightsize (0.35); color ("#ffb24a"); tint ("#ff5a18"); rate (40); light (1.1); smoke ({"darkness":0.3,"rate":3}); embers (false)
campfirecampfire: flames, embers, a warm light, a little smokesize (0.7); color ("#ffae45"); tint ("#ff4e12"); rate (45); light (1.8); smoke ({"darkness":0.45,"rate":6}); embers (true)
embersembers: glowing embers rising off something burningsize (1); rate (8); color ("#ff8a30"); radius (0.6)
burning-groundburning-ground: ground on fire over a radius: low flames, smoke, a light, scorched afterradius (2); color ("#ffa640"); tint ("#ff4010"); rate (25); light (1.6); scorch (true)
fire-trailfire-trail: fire left behind what moves: flames that burn out, embers, smoke, scorched ground. On a unit, it followssize (1); color ("#ffae3c"); tint ("#ff3d0c"); rate (70); light (1.2); smoke, embers, scorch (true)

Smoke ​

EffectIts knobs
smokesmoke: a column rising and drifting with the windsize (1); darkness (0.4): 0 white steam to 1 black smoke; rate (12); color ("#b4aea5")
puffpuff: one puff: a shot, a landing, a unit appearingsize (1); color ("#bdb6aa"); amount (10)
chimneychimney: thin smoke from a chimney, a pipe, a lampsize (0.45); darkness (0.35); rate (4); color ("#9c968e")
smoke-trailsmoke-trail: smoke left behind what flies or burns (a rocket, a flaming piece)size (1); rate (30); color ("#57524c")

Explosions ​

EffectIts knobs
explosionexplosion: a flash, a fireball, sparks and smoke, a shockwave, a light, the view shaken, the ground scorchedsize (1); color ("#ffb24a"): the fireball's heart; tint ("#ff4a10"): its edge and sparks; light (5); shake (0.6): 0 for none; scorch (true); sound (none): a sound of the game's (GameView.sounds)
shockwaveshockwave: a ring flung out along the ground, with dustsize (1); color ("#fff0d0"); dust (true)
fireballfireball: a white-hot heart in rolling flames, sparks, smoke, a streak. Moved, it trails; impact is what it lands withsize (1); color ("#ffc24a"); tint ("#ff4a0c"); light (1.8); smoke, streak (true); impact ("explosion"); impactSize (0.6)
impact-ringimpact-ring: a flash and two rings racing out over the ground, dust and sparks, the ground crackedsize (1); color ("#ffe4a8"); tint ("#ff8a2a"); speed (1); light (3); shake (0.35); dust, sparks, crack (true); sound (none)
spark-burstspark-burst: sparks flung out: steel on steel, a hammer on stonesize (1); count (24); color ("#ffd27a"); sound (none)

Dust and earth ​

EffectIts knobs
dustdust: a cloud thrown up: an impact, a fall, a building coming downsize (1); amount (18); color ("#9a8466"); bits (true): bits of dirt fly too
dust-traildust-trail: dust kicked up behind feet or wheels. On a unit, it followssize (1); rate (14); color ("#a08a6a")
leavesleaves: leaves flung up and fluttering down (FoliageLook.leaves, a tree struck)size (1); amount (10); color ("#4f7a2a"); tint ("#a8a03a"): the odd dry leaf
rubble-fallrubble-fall: rubble falling from a height, dust where it landssize (1); height (3); amount (24); color ("#8a7a68")
ground-crackground-crack: the ground cracked open, dust and bits thrown upsize (1); color ("#2c241c"); time (20): how long the cracks stay

Magic ​

EffectIts knobs
glowglow: a soft breathing orb with its light: a wisp, a lantern of magicsize (1); color ("#7fd0ff"); light (1); height (1)
sparklesparkle: twinkles of light: treasure, a blessingsize (1); color ("#fff2a0"); rate (14)
auraaura: a turning ring of light under a unit, motes risingsize (1); color ("#ffd76a")
beambeam: a pillar of light from the skysize (1); color ("#fff4c0"); height (12); light (3)
portalportal: a swirl on the ground, motes drawn in, its lightsize (1); color ("#b07aff"); light (2)
healheal: ribbons winding up a unit, a column of light, rising rings, crosses, a green glow and flashsize (1); color ("#42ff6e"); accent ("#f0ffd0"); rate (40); light (2.2); rings (3); spirals (true); crosses (true); sound (none)
essenceessence: ribbons of magic circling a unit, weaving over and under, sparkles trailing, closing in and gonesize (1); palette (eight colours); strands (5, up to 8); time (4); fade (1.6); turns (0.8) a second; radius (1); flat (0.5); wave (1); height (1); width (1); sparkles (30); light (1.2)
sunburstsunburst: turning rays of sunlight around a unit, a bright heart, the ground litsize (1); color ("#ffe9a0"); tint ("#ffb43c"); rays (22); spin (0.25); height (1.1); light (3)
lightninglightning: a bolt striking, a flash, sparks, the view shakensize (1); color ("#bfe0ff"); light (8); shake (0.4); sound (none)
frostfrost: a burst of cold, glinting ice, a ring of rime on the groundsize (1); color ("#bfeaff")
poison-cloudpoison-cloud: a low drifting cloud of poisonradius (2.5); color ("#b8f060"); rate (12)
gas-cloudgas-cloud: thick green gas rolling low, a sickly glow, fumes, bubbles popping, its edge markedradius (3); color ("#5f9e2a"); tint ("#c6ff4a"); density (1); bubbles (14); height (1); light (0.8); edge (true)

Water ​

EffectIts knobs
splashsplash: drops thrown up and a ring of ripplesize (1); color ("#d6ecff"); sound (none)
rippleripple: rings spreading on still watersize (1); color ("#d6ecff"); rate (1.2)
mistmist: mist lying low: a waterfall's spray, a marshradius (3); color ("#eef4f8"); rate (6); opacity (0.3)

Blood ​

EffectIts knobs
blood-sprayblood-spray: blood from a hit or death: long drops, finer ones, globs, a red mistamount (14); color ("#730508"); tint ("#400305"); speed (3.5); height (1); size (1); mist (true)
blood-burstblood-burst: an explosion of blood: jets, mist, chunks, the ground splatteredsize (1); amount (120); color ("#7a0609"); tint ("#3e0204"); speed (6); height (0.9); mist, chunks, splatter (true); shake (0.1); sound (none)
blood-splatterblood-splatter: splats thrown over the ground, a pool, drops, drying awaysize (1); count (9); spread (1.8); color ("#2c0103"); seconds (25); drops (true)
blood-poolblood-pool: a pool of blood drying awaysize (1.1); color ("#730508"); seconds (30)

The client's blood (GameView.units.blood) plays blood-spray, blood-pool where a unit falls, and blood-splatter away from the blow (BloodLook.spray, bloodFor).