Show an effect
Name effects in the view (GameView.fx.defs), then play them from the rules (everyone who sees the place sees it, in replays too) or from the screen alone.
ts
// in src/game.ts
import { fx, type GameView } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { rules } from './rules'
export const view: GameView = {
units: {
looks: {}
},
fx: {
defs: {
// the game's own, from parts: a burst of sparks, a flash of light, a shake, a scorch on the ground
'mine.blast': {
params: { size: 1 },
knobs: { size: { min: 0.2, max: 4, step: 0.1, about: 'How big the blast is' } },
parts: [
{
particles: {
bursts: [{ at: 0, count: 60 }],
shape: 'sphere',
speed: [4, 9],
lifetime: [0.3, 0.8],
size: [0.6, 0.1],
color: ['#fff2c0', '#ff6020'],
gravity: 4
}
},
{ light: { color: '#ffb060', intensity: (p) => 4 * p.size, range: 8, fade: 0.6 } },
{ shake: (p) => ({ strength: 0.4 * p.size, time: 0.3 }) },
{ at: 0.1, decal: { size: (p) => 3 * p.size, time: 40 } }
]
},
// one of the ready-made ones, with its knobs
'mine.smoke': fx.particles({ rate: 30, lifetime: [2, 4], speed: [0.5, 1], size: [0.8, 2], color: ['#777', '#333'] })
}
},
// the game's own events, reacted to on the screen: an effect where the event says, a sound, a shake
on: {
'mine.exploded': { fx: 'mine.blast', params: (event) => ({ size: (event as { power: number }).power }), sound: 'boom', shake: 0.6 }
}
}
export const game = createGame(rules).view(view)Done: a mine.exploded event from your rules now plays a blast, a sound and a shake.
Play it from the rules
ts
// in src/rules.ts
const id = world.fx('mine.blast', { at: { x: 40, z: 22 }, params: { size: 2 } })
world.fx('mine.smoke', { on: house.id, point: 'roof' }) // follows the entity, ends with it
world.stopFx(id, { fade: 1 })Play it on the screen only
For a button press or a tooltip, with nothing in the world's state:
ts
const blast = kit.fx.play('mine.blast', { at: { x: 40, z: 22 }, params: { size: 2 } })
blast.stop({ mode: 'fade', fade: 1 })In the editor
- Open the Effects panel. It lists your effects and the ready-made ones (
presetFx). - Pick one: it plays on a stage, with a slider for each knob.
- Tune it. The panel writes
fx.json, which the view lays over its code. - To place one on the map, use the effect tool (X).
Reference
| Part | What it does |
|---|---|
particles | Bursts or a stream of particles. |
light | A light that fades. |
shake | Shakes the camera. |
decal | A mark on the ground. |
at | Delay before the part starts, in seconds. |
params | Values a caller passes in; parts read them as p. |
knobs | Sliders the editor shows for each param. |
Effects and particles has every part and the ready-made effects. Cinematics plays effects on a cinematic's clock.