Skip to main content

Particles

PixelStorm's particle system creates lightweight entities for visual effects. The implementation is simple on purpose: particles are just engine entities with their own transform, sprite, and particle state.

Particle

Particle stores the state of a live particle.

FieldUse
Velocitycurrent velocity
Lifetimetotal lifetime
Agetime already lived
StartColor / EndColorcolor interpolation
StartScale / EndScalescale interpolation
GravityScaleper-particle gravity

Defaults

FieldDefault
Lifetime1.0f
Age0.0f
StartColoropaque white
EndColortransparent white
StartScale(4, 4)
EndScale(1, 1)
GravityScale0.0f

ParticleEmitter

ParticleEmitter defines how particles are spawned.

FieldDefaultUse
Activetruewhether it can emit
Loopfalsewhether it auto-emits cyclically
AutoEmitfalsewhether it emits over time
BurstCount8particles per burst
EmitRate0.0fbursts per second
Lifetime0.75flifetime of each particle
Speed80.0fbase speed
SpeedVariation20.0frandom variation
Spread180.0fangular spread
RenderOrder0draw layer

ParticleEmitterProxy

Entity::Particles() returns the emitter control proxy.

MethodUse
Play()enables automatic emission
Pause()pauses without clearing pending bursts
Stop()stops and clears pending bursts
IsPlaying()active state
IsLooping() / SetLoop()auto-emission loop
IsAutoEmitting() / SetAutoEmit()continuous emission
GetBurstCount() / SetBurstCount()burst size
GetEmitRate() / SetEmitRate()emission rate
GetLifetime() / SetLifetime()lifetime
GetSpeed() / SetSpeed()base speed
GetSpeedVariation() / SetSpeedVariation()variation
GetSpread() / SetSpread()spread
GetStartColor() / SetStartColor()start color
GetEndColor() / SetEndColor()end color
GetStartScale() / SetStartScale()start scale
GetEndScale() / SetEndScale()end scale
GetGravityScale() / SetGravityScale()gravity
GetTexture() / SetTexture()texture name
GetRenderOrder() / SetRenderOrder()draw order
EmitBurst(count)requests extra bursts

EmitBurst

  • count <= 0 is ignored
  • bursts are accumulated in PendingBursts
  • the system consumes them on the next update

System

ParticleSystem:

  • spawns particles from active emitters
  • animates color, scale, and position
  • destroys expired particles

Example

Entity fx = GetWorld().CreateParticleEmitter(
"Dust",
Vec2(200.0f, 180.0f),
"spark",
8,
0.5f,
90.0f,
20.0f,
180.0f,
Vec4(1.0f, 0.8f, 0.2f, 1.0f),
Vec4(1.0f, 0.2f, 0.0f, 0.0f));

fx.Particles().EmitBurst(12);
note

Particles are rendered as normal entities with Transform, SpriteRenderer, and Particle. That makes them easy to integrate with the existing renderer.