Skip to content

Respect particleSizes for ParticleShape.Image particles - #27

Merged
PiotrPrus merged 4 commits into
mainfrom
fix/image-particle-size
Jul 3, 2026
Merged

PiotrPrus merged 4 commits into
mainfrom
fix/image-particle-size

Conversation

@PiotrPrus

Copy link
Copy Markdown
Owner

Summary

Fixes #23. particleSizes had no effect for ParticleShape.Image: the bitmap was always drawn at its intrinsic pixel size, so image particles couldn't be sized via the config the way Circle and PathShape can.

Now the bitmap is drawn into a destination box sized from canvasParticle.size (converted to px) using drawImage(dstOffset, dstSize), with scale/rotation applied on top. Image particles are size-consistent with every other shape and independent of the source asset's resolution.

Changes

  • ui/ParticleShapeExtensions.kt — fixed the live is ParticleShape.Image -> branch in DrawScope.draw and the ParticleShape.Image.draw extension (kept consistent).
  • CanvasEmitterConfig.kt — clarified the particleSizes KDoc to state it applies to image particles too.

Behavior change

⚠️ This changes rendered output for anyone relying on intrinsic-size image rendering — image particles now honor particleSizes instead of the bitmap's pixel dimensions. (No CHANGELOG.md in the repo, so noting it here.)

Testing

  • :particle-emitter:compileKotlinMetadata compiles cleanly.
  • Verified live on a Pixel 9a emulator with the Canvas Emitter sample: its star_four.png (10×10 px) with particleSizes = 8.dp now renders as crisp, correctly-sized stars scaled to the configured size rather than the raw 10px bitmap.

🤖 Generated with Claude Code

PiotrPrus and others added 4 commits July 3, 2026 09:09
Image particles were always drawn at the bitmap's intrinsic pixel size,
so particleSizes had no effect and there was no config knob to control
how big image particles appear (unlike Circle/PathShape).

Draw the bitmap into a destination box sized from canvasParticle.size
(converted to px) via drawImage(dstOffset, dstSize), with scale/rotation
applied on top. Image particles are now size-consistent with every other
shape and independent of the source asset's resolution.

Applied to both the live render branch in DrawScope.draw and the
ParticleShape.Image.draw extension. Updated the particleSizes KDoc.

Note: this is a behavior change for anyone relying on intrinsic-size
image rendering.

Closes #23

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Give the star particles a long lifespan (4-6s) and a large scale ramp
(1x to ~5x) so the per-particle size change is easy to watch. This makes
the particleSizes fix for image particles visually obvious: stars start
at the configured size and grow smoothly instead of being locked to the
bitmap's intrinsic pixels.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Keep the resized/growing star particles (10.dp base + 1x->5x scale ramp)
but revert lifespan, fade, scale duration, force, and birth rate to their
original short-lived values so the sample is back to a snappy burst.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Use a mix of particleSizes (3/5/7/9.dp) and a gentler 1x->2x scale ramp
so the sample shows a natural spread of star sizes while still exercising
the image-resize fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PiotrPrus
PiotrPrus merged commit 5c75445 into main Jul 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

particleSizes is ignored for ParticleShape.Image (should resize the bitmap)

1 participant