Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Take in super.curve in ScalingParticle #3220

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/flame/rendering/particles.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ game.add(
particle: ScalingParticle(
lifespan: 2,
to: 0,
curve: Curves.easeIn,
child: CircleParticle(
radius: 2.0,
paint: Paint()..color = Colors.red,
Expand Down
9 changes: 7 additions & 2 deletions packages/flame/lib/src/particles/particle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@ abstract class Particle {
/// Wraps this particle with a [ScalingParticle].
///
/// Allows for changing the size of this particle and/or its children.
ScalingParticle scaling({double to = 0}) {
return ScalingParticle(to: to, child: this, lifespan: _lifespan);
ScalingParticle scaling({double to = 0, Curve curve = Curves.linear}) {
return ScalingParticle(
to: to,
child: this,
lifespan: _lifespan,
curve: curve,
);
}
}
1 change: 1 addition & 0 deletions packages/flame/lib/src/particles/scaling_particle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ScalingParticle extends CurvedParticle with SingleChildParticle {
required this.child,
this.to = 0,
super.lifespan,
super.curve,
});

double get scale => lerpDouble(1, to, progress) ?? 0;
Expand Down
6 changes: 4 additions & 2 deletions packages/flame/test/particles/scaling_particle_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void main() {
),
);

final particle = rect.scaling(to: .5);
final particle = rect.scaling(to: .5, curve: Curves.easeIn);

final component = ParticleSystemComponent(
particle: particle,
Expand All @@ -28,7 +28,9 @@ void main() {
await game.ready();
game.update(1);

expect(particle.scale, .75);
expect(particle.scale, .841796875);
expect(particle.curve, Curves.easeIn);
expect(particle.progress, 0.31640625);
expect(particle.child, isInstanceOf<ComputedParticle>());
expect(particle.child.progress, 0.5);
});
Expand Down
Loading