particle

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Emitter

type Emitter struct {
	Config    EmitterConfig
	Particles []particle
	Alive     int
	EmitAccum float64
	Active    bool
	// World-space tracking: the emitter's last known world position,
	// set by the update walk so particles can be spawned at world coords.
	WorldX, WorldY float64
}

Emitter manages a pool of particles with CPU-based simulation.

func NewEmitter

func NewEmitter(cfg EmitterConfig) *Emitter

NewEmitter creates an Emitter with a preallocated pool.

func (*Emitter) AliveCount

func (e *Emitter) AliveCount() int

AliveCount returns the number of alive particles.

func (*Emitter) Bounds

func (e *Emitter) Bounds() types.Rect

Bounds returns the axis-aligned bounding box of all alive particles in the emitter's coordinate space (local for local-space, world for world-space). The returned rect includes particle scale so the full rendered extent is covered. Returns a zero Rect when no particles are alive.

func (*Emitter) IsActive

func (e *Emitter) IsActive() bool

IsActive reports whether the emitter is currently emitting new particles.

func (*Emitter) ParticleAlpha

func (e *Emitter) ParticleAlpha(i int) float32

ParticleAlpha returns the alpha of the particle at the given index.

func (*Emitter) ParticleColor

func (e *Emitter) ParticleColor(i int) (r, g, b float32)

ParticleColor returns the RGB color of the particle at the given index.

func (*Emitter) ParticleLifeFraction

func (e *Emitter) ParticleLifeFraction(i int) float64

ParticleLifeFraction returns the progress fraction (0..1) of the particle's lifetime.

func (*Emitter) ParticlePos

func (e *Emitter) ParticlePos(i int) (x, y float64)

ParticlePos returns the position of the particle at the given index.

func (*Emitter) ParticleRenderData

func (e *Emitter) ParticleRenderData(i int) (x, y float64, scale, alpha, colorR, colorG, colorB float32)

ParticleRenderData returns position, scale, and color for particle at index i. Used by the render pipeline's batch submitter to build per-particle vertices.

func (*Emitter) ParticleScale

func (e *Emitter) ParticleScale(i int) float32

ParticleScale returns the scale of the particle at the given index.

func (*Emitter) ParticleVelocity

func (e *Emitter) ParticleVelocity(i int) (vx, vy float64)

ParticleVelocity returns the velocity of the particle at the given index.

func (*Emitter) Reset

func (e *Emitter) Reset()

Reset stops emitting and kills all alive particles.

func (*Emitter) Start

func (e *Emitter) Start()

Start begins emitting particles.

func (*Emitter) Stop

func (e *Emitter) Stop()

Stop stops emitting new particles. Existing particles continue to live out.

func (*Emitter) Update

func (e *Emitter) Update(dt float64)

Update advances particle simulation by dt seconds.

type EmitterConfig

type EmitterConfig struct {
	// MaxParticles is the pool size. New particles are silently dropped when full.
	MaxParticles int
	// EmitRate is the number of particles spawned per second.
	EmitRate float64
	// Lifetime is the range of particle lifetimes in seconds.
	Lifetime types.Range
	// Speed is the range of initial particle speeds in pixels per second.
	Speed types.Range
	// Angle is the range of emission angles in radians.
	Angle types.Range
	// StartScale is the range of scale factors at birth, interpolated to EndScale over lifetime.
	StartScale types.Range
	// EndScale is the range of scale factors at death.
	EndScale types.Range
	// StartAlpha is the range of alpha values at birth, interpolated to EndAlpha over lifetime.
	StartAlpha types.Range
	// EndAlpha is the range of alpha values at death.
	EndAlpha types.Range
	// Gravity is the constant acceleration applied to all particles each frame.
	Gravity types.Vec2
	// StartColor is the tint at birth, interpolated to EndColor over lifetime.
	StartColor types.Color
	// EndColor is the tint at death.
	EndColor types.Color
	// Region is the TextureRegion used to render each particle.
	Region types.TextureRegion
	// BlendMode is the compositing operation for particle rendering.
	BlendMode types.BlendMode
	// WorldSpace, when true, causes particles to keep their world position
	// once emitted rather than following the emitter node.
	WorldSpace bool
}

EmitterConfig controls how particles are spawned and behave.

Jump to

Keyboard shortcuts

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