fxfile

package
v0.0.0-...-94fff03 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fxfile reads, checks and writes the *.fx.json particle effect file, without Ebiten, the ECS runtime or any GPU work: the authored emitters (Emitter, Spec), Decode and Encode.

Package particles' asset loader, the fx tool (editor/fxedit) and `wpix mcp` all use this package, so they cannot disagree about what a valid effect file is. It imports gfx (for the blend, shape, color and vector types the gfx.Particles overrides share) and xmath only.

The format reference is doc/guide/engine/particles.md#the-effect-file.

Index

Constants

View Source
const MaxEmitters = 8

MaxEmitters is the most emitters one effect file may hold.

View Source
const Suffix = ".fx.json"

Suffix is the file name suffix of a particle effect. The asset kind is "effect".

View Source
const Version = 0

Version is the only format version this package reads and writes.

Variables

This section is empty.

Functions

func BlendNames

func BlendNames() []string

BlendNames returns the names of the blend modes the file accepts, in the order of gfx.Blend.

func Encode

func Encode(s Spec) []byte

Encode returns the canonical text of s: two-space indented, a trailing newline, keys in a fixed order, hex colors, names for the enums and degrees for the angles. Decode(Encode(s)) is s for any s Decode accepts.

func ShapeNames

func ShapeNames() []string

ShapeNames returns the names of the emit shapes the file accepts, in the order of gfx.EmitShape.

Types

type Emitter

type Emitter struct {
	// Name labels the emitter in tools; the simulation ignores it.
	Name string
	// Layer is added to gfx.Particles.Layer when the emitter's particles
	// are drawn, so one effect can put smoke behind sparks. Emitters with
	// equal layers draw in file order, the first below.
	Layer int16
	// Sprite is the asset key of the particle image; "" draws the
	// placeholder.
	Sprite string
	// Shader is the asset key of a Kage shader that draws every particle; ""
	// draws them normally. It gets the particle sprite as imageSrc0, the
	// particle's tint (with its fades) as the color argument of Fragment and
	// Params as its "Params" vec4. Shaded particles cost one draw call each.
	Shader string
	// Params are passed to Shader as its "Params" vec4 uniform, the same for
	// all particles.
	Params [4]float32
	// Blend is how the particles are composited onto what is below them.
	Blend gfx.Blend
	// Color tints the particle at birth. Zero means white.
	Color gfx.Color
	// EndColor is the tint at death; the color blends linearly over the
	// life. Zero means Color (no change).
	EndColor gfx.Color
	// Scale is the particle size at birth. Zero means 1.
	Scale float32
	// EndScale is the size at death. Zero means Scale (no change).
	EndScale float32
	// FadeIn is the fraction of the life over which alpha ramps up from 0.
	FadeIn float32
	// FadeOut is the fraction of the life, at its end, over which alpha
	// ramps down to 0.
	FadeOut float32

	// Rate is the number of particles spawned per second. A fractional
	// remainder carries over to the next tick.
	Rate float32
	// Burst is the number of particles spawned at the start of each cycle.
	Burst uint16
	// Duration is the length of a cycle in seconds. Zero means forever.
	Duration float32
	// Loop restarts the cycle after Duration (and spawns the Burst again).
	Loop bool
	// Max is the pool capacity: spawns beyond it are dropped. Zero means 256.
	Max uint16

	// Shape is the area particles spawn in.
	Shape gfx.EmitShape
	// ShapeSize is the radius (in X) of gfx.EmitCircle or the width and
	// height of gfx.EmitRect.
	ShapeSize gfx.Vec2

	// LifeMin and LifeMax bound the lifetime in seconds. A LifeMax below
	// LifeMin (including zero) means LifeMin.
	LifeMin, LifeMax float32
	// Angle is the emission direction in radians, clockwise on screen from
	// +X, relative to the entity's Transform: Transform.Rot adds to it.
	Angle float32
	// Spread is the full cone width around Angle in radians.
	Spread float32
	// SpeedMin and SpeedMax bound the initial speed in units/s.
	SpeedMin, SpeedMax float32
	// Gravity is the constant acceleration in units/s².
	Gravity gfx.Vec2
	// Drag slows particles down by this factor per second.
	Drag float32
	// SpinMin and SpinMax bound the rotation speed in rad/s.
	SpinMin, SpinMax float32
	// RandomRotation gives each particle a random start rotation.
	RandomRotation bool
	// Local makes particles move with the emitter instead of staying where
	// they spawned.
	Local bool
}

Emitter is the authored description of one particle emitter, in the units the simulation uses: radians, world units and seconds. Decode converts from the file's readable units and Encode back.

Every zero value does something sensible, so an emitter with only Sprite and Rate set emits visible particles: Color zero is white, EndColor zero is Color, Scale zero is 1, EndScale zero is Scale, a zero Max is 256, and no lifetime at all is 1 second.

type Spec

type Spec struct {
	Emitters []Emitter
}

Spec is the contents of an *.fx.json file: the effect's emitters, between one and MaxEmitters. They play together on one entity.

func Decode

func Decode(data []byte) (Spec, error)

Decode parses and checks an *.fx.json file. Unknown keys and bad values are errors, and every problem of the file is reported together, one per line, each starting with the path of the value ("emitters[0].blend").

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL