Visual effects in Flame (particles, effects, decorators, shaders)
flameparticlesshadersglslpost-processingparallaxpixel-art
Flame ships most of what a 2D game needs for visual polish without extra packages. This is the toolbox as researched for Run (2026-03, flame ^1.36) plus patterns that worked.
Built-in systems
- Particles (
ParticleSystemComponent):AcceleratedParticle(gravity, damping),CircleParticle,ScalingParticle,ComputedParticle(custom render callback),Particle.generate(count:, generator:). Lightweight canvas draws, auto-removed at end of lifespan, safe to add fromupdate(). Keep live particles under ~200. - Effects on components:
ScaleEffect(squash/stretch),OpacityEffect,ColorEffect(damage flash),GlowEffect(usesMaskFilter.blur, expensive),MoveEffect,SequenceEffect, all driven byEffectController(duration, reverse, infinite, curve). - Decorators (render-time):
PaintDecorator.blur/tint/grayscale,Rotate3DDecorator,Shadow3DDecorator. Blur usessaveLayer(), so use sparingly on mobile. - Post-processing:
PostProcesssubclasses,PostProcessComponentfor a subtree,CameraComponent.postProcessfor full screen,PostProcessSequentialGroupto chain. Declare.fragfiles underflutter: shaders:in pubspec,#include <flutter/runtime_effect.glsl>, useFlutterFragCoord()notgl_FragCoord.rasterizeSubtree()does a fulltoImageSync(), so avoid it per frame. - Useful packages:
flame_camera_tools(shake, zoom, smooth follow),flutter_animate(menu stagger),flame_lottie. - Not production ready (2026):
flutter_gpu,flutter_scene,flame_3d.
Shader ideas for a neon look
Bloom (extract bright -> blur -> composite), CRT scanlines (sin(y * pi * 2) darkening +
barrel distortion), chromatic aberration (offset R/G/B), vignette, heat haze (animated sine
UV offset).
Pseudo-3D without 3D
Multi-layer parallax (Run uses factors 0.01, 0.08, 0.28), foreground layers with parallax
above 1.0, smaller sprites for depth, desaturated far layers, stretched shadow copies,
Mode 7 floors via a fragment shader, sprite stacking for voxel-like objects. Cache static
backgrounds as a texture (Flame Snapshot mixin).
Patterns that worked in Run
- Afterimages: draw the current sprite as a silhouette with
ColorFilter.mode(tint, BlendMode.srcIn), spawn one every 0.03 s while dashing, fade from ~0.55 alpha over ~0.28 s. Spawn as world children (not player children) so they stay put. - Jump ring: expanding ellipse (radius 6 -> 26) under the feet on a double jump.
- Dust bursts on jump, wall kick, and wall slide; make the "feet" position gravity-flip aware.
- Procedural backgrounds beat data-driven ones: a simple layer/element data model cannot
express seeded random scenery, particles, or complex animation. Built-in themes use a
Component per background. Draw relative to the camera:
sl = cam.x - viewportW/2; st = cam.y - viewportH/2, then offset by parallax. Two QA bugs came from forgetting this: base rects at a hardcoded (0,0) detached from the camera, and a trail stored in world coordinates but drawn in local space was invisible. - Pixel art: render with
FilterQuality.none(via an override paint) for crisp pixels; flip horizontally with canvas save/translate/scale; drive frames withSpriteAnimationTicker.
See also
- Game juice and polish techniques
- Flutter / Flame canvas rendering performance facts
- Zero-allocation render and update loops