Skip to content

Add EmitTo for particles that travel to a target - #3

Merged
mos379 merged 1 commit into
mainfrom
feature/emit-to
Oct 15, 2026
Merged

mos379 merged 1 commit into
mainfrom
feature/emit-to

Conversation

@mos379

@mos379 mos379 commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Emit (2.1.0) throws particles outward and lets physics take them. That says something happened, but not where it went. A reward landing on a score counter, an item going into a basket, is a flight with a destination and a moment of arrival.

API

MyParticleCanvas.EmitTo(itemCentre, scoreCounter, onArrived: () => Score += 10);
EmitTo(SKPoint from, SKPoint to, …) canvas pixels
EmitTo(Point from, Point to, …) device-independent units

Optional color, size, durationMillis, arcHeight (fraction of distance; 0 is a straight line).

How it moves

FlyingStarParticle follows a quadratic Bézier with the control point lifted perpendicular to the flight, so it lobs rather than slides. It spins throughout, shrinks ~30% on approach, and fades over the final 15% so it dissolves into the target instead of stopping dead. Arrived fires on the landing frame; EmitTo marshals the callback to the main thread.

One change worth reviewing

ParticleBase gains IsFinished, and the animation loop now removes particles that report it:

_particles.RemoveAll(particle => particle.IsFinished || !canvasRect.Contains(…));

Until now a particle was only ever removed by leaving the view — and one that flies to a target lands inside it, so it would never be cleaned up. Existing particles return false and are unaffected.

TransformationMatrix moved from private set to protected set so a subclass can drive its own motion; the getter is unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_012fvKRoJiVhmmARSE8k7Vtf

Every effect so far throws particles and lets them go, which can say that
something happened but not where it went. A reward landing on a score, an
item going into a basket, is a flight with a destination and a moment of
arrival.

FlyingStarParticle follows a quadratic bezier from origin to destination,
the control point lifted perpendicular to the flight so it lobs rather
than sliding, spinning throughout, shrinking slightly on approach and
fading over the final stretch so it dissolves into the target instead of
stopping dead. It raises Arrived on the frame it lands, and EmitTo
marshals that onto the main thread so the target can react there and then.

ParticleBase gains IsFinished, and the animation loop removes particles
that report it. Until now a particle was only removed by leaving the view,
and one that flies to a target lands inside it.
@mos379
mos379 merged commit 921e41c into main Oct 15, 2026
1 check passed
@mos379
mos379 deleted the feature/emit-to branch October 15, 2026 22:18
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.

1 participant