From 0fbc73ccdf36938a20f2eb8ae544881a8dbeae1e Mon Sep 17 00:00:00 2001 From: Anonymous Dev <15832303+duck-dev-go@users.noreply.github.com> Date: Thu, 11 Jul 2024 22:08:49 +0200 Subject: [PATCH] feat: Take in super.curve in ScalingParticle (#3220) # feat: Take in curve parameter in ScalingParticle This PR introduces a `curve` parameter to the `ScalingParticle` class. This allows for more flexible and customizable scaling by specifying different curves for scaling transformations. The default curve is set to `Curves.linear`, ensuring backward compatibility. ## Checklist - [x] I have followed the [Contributor Guide] when preparing my PR. - [x] I have updated/added tests for ALL new/updated/fixed functionality. - [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`. - [x] I have updated/added relevant examples in `examples` or `docs`. ## Breaking Change? - [ ] Yes, this PR is a breaking change. - [x] No, this PR is not a breaking change. --- doc/flame/rendering/particles.md | 1 + packages/flame/lib/src/particles/particle.dart | 9 +++++++-- packages/flame/lib/src/particles/scaling_particle.dart | 1 + packages/flame/test/particles/scaling_particle_test.dart | 6 ++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/flame/rendering/particles.md b/doc/flame/rendering/particles.md index 448d66c5fdf..54a953c39f3 100644 --- a/doc/flame/rendering/particles.md +++ b/doc/flame/rendering/particles.md @@ -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, diff --git a/packages/flame/lib/src/particles/particle.dart b/packages/flame/lib/src/particles/particle.dart index b8a669f414d..50e1b53388d 100644 --- a/packages/flame/lib/src/particles/particle.dart +++ b/packages/flame/lib/src/particles/particle.dart @@ -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, + ); } } diff --git a/packages/flame/lib/src/particles/scaling_particle.dart b/packages/flame/lib/src/particles/scaling_particle.dart index 524e7aab5c0..9e55a242522 100644 --- a/packages/flame/lib/src/particles/scaling_particle.dart +++ b/packages/flame/lib/src/particles/scaling_particle.dart @@ -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; diff --git a/packages/flame/test/particles/scaling_particle_test.dart b/packages/flame/test/particles/scaling_particle_test.dart index 3b6662181af..dd0b3c07fc7 100644 --- a/packages/flame/test/particles/scaling_particle_test.dart +++ b/packages/flame/test/particles/scaling_particle_test.dart @@ -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, @@ -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()); expect(particle.child.progress, 0.5); });