Library API
Render effects
pixelkiln vfx is a thin layer over exported functions. The local source,
pixelfx, is not a dependency of
PixelKiln: install it yourself with npm i github:patch-gg/pixelfx.
import { loadPixelfx, listPixelfxEffects, makePixelfxVfx, renderPixelfx } from "pixelkiln"
const lib = await loadPixelfx()
const standalone = listPixelfxEffects(lib).filter((effect) => !effect.needsCharacter)
const made = await makePixelfxVfx(lib, {
effect: "fire/torch",
fps: 12,
options: { seed: 4, palette: ["#102", "#43a", "#8cf", "#fff"] },
out: "fx/torch",
})
console.log(made.paths.sheet, made.anchor, made.frames, made.sheetSha256)
const { frames, width, height, anchor } = renderPixelfx(lib, { effect: "pickups/coin-spin", margin: 4 })
loadPixelfx(from?)looks for the library from the working directory, then from PixelKiln's own install, and throws aPixelKilnErrorwith codecapabilityand the install line as itshintwhen it is missing. Pass directories to look from somewhere else.listPixelfxEffects(lib)returns each effect's id, category, frame size, duration,loop, defaultfps, declaredoptions, andneedsCharacter.renderPixelfx(lib, recipe)renders in process and writes nothing. It returnsframes(one RGBABufferper frame, straight alpha),width,height,fps,loop, andanchor, the effect's pivot on a frame.makePixelfxVfx(lib, { ...recipe, out, name?, force? })writes<out>.png,<out>.json, and<out>.vfx.jsonand returns their paths and the frame facts.readPixelfxRecipe(file)reads a recipe back from that record, or returnsnullfor a file that is not a pixelfx recipe.- A recipe is
{ effect, fps?, margin?, options? }.optionsgoes to the effect over its defaults:palette,seed,flip,angle,light, and the effect's own. Effects drawn around pixelfx's stock character are refused with ausageerror.
A second local source, pixel-vfx-codex,
has the same shape and is installed the same way
(npm i github:888wing/pixel-vfx-codex):
import { loadCodex, listCodexEffects, makeCodexVfx, renderCodex } from "pixelkiln"
const lib = loadCodex()
const effects = listCodexEffects(lib) // id, name, category, and each parameter's range
const made = await makeCodexVfx(lib, {
effect: "fireball",
camera: "25d",
params: { tailLength: 1.6 },
hue: 40,
out: "fx/fireball",
})
const { frames, width, height, anchor, fps } = renderCodex(lib, { effect: "healing-field" })
loadCodex(from?)is synchronous. It evaluates the package's engine and effect files in a separatevmcontext and throws acapabilityerror with the install line as itshintwhen the package is missing.- A recipe is
{ effect, camera?, fps?, margin?, hue?, params?, tune? }.planCodex(lib, recipe)gives the frame count without rendering, andcheckCodexRecipethrows ausageerror for an unknown effect, parameter or knob, or a value out of range. renderCodexandmakeCodexVfxmatch their pixelfx counterparts: frames on transparency cropped to one box, the pivot inanchor, and the same three files.readCodexRecipe(file, { bare? })reads a record back.writeLocalVfxandlocalSheetare the shared writer both sources use.
The PixelLab side has the same shape: makeVfx(mcpClientFromEnv(), { preset, parts, sprite, fps, out }) drives the free workbench, and
makeVfxWithArtist(clientFromEnv(), { description, out }) asks the paid
artist. Both write the files vfx documents.
