Skip to content

Commit

Permalink
feat: Add position and anchor params for Sprite and SpriteAnimation P…
Browse files Browse the repository at this point in the history
…articles (#2370)
  • Loading branch information
gtgalone committed Feb 28, 2023
1 parent 5b07bd5 commit 181e0b5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions doc/flame/rendering/particles.md
Expand Up @@ -300,9 +300,10 @@ game.add(
```


## AnimationParticle
## SpriteAnimationParticle

A `Particle` which embeds an `Animation`. By default, aligns the `Animation`'s `stepTime` so that
A `Particle` which embeds a `SpriteAnimation`.
By default, aligns the `SpriteAnimation`'s `stepTime` so that
it's fully played during the `Particle` lifespan. It's possible to override this behavior with the
`alignAnimationTime` argument.

Expand All @@ -314,7 +315,7 @@ final spritesheet = SpriteSheet(
game.add(
ParticleSystemComponent(
particle: AnimationParticle(
particle: SpriteAnimationParticle(
animation: spritesheet.createAnimation(0, stepTime: 0.1),
);
),
Expand Down
2 changes: 1 addition & 1 deletion packages/flame/lib/particles.dart
@@ -1,6 +1,5 @@
export 'src/anchor.dart';
export 'src/particles/accelerated_particle.dart';
export 'src/particles/animation_particle.dart';
export 'src/particles/circle_particle.dart';
export 'src/particles/component_particle.dart';
export 'src/particles/composed_particle.dart';
Expand All @@ -12,5 +11,6 @@ export 'src/particles/paint_particle.dart';
export 'src/particles/particle.dart';
export 'src/particles/rotating_particle.dart';
export 'src/particles/scaled_particle.dart';
export 'src/particles/sprite_animation_particle.dart';
export 'src/particles/sprite_particle.dart';
export 'src/particles/translated_particle.dart';
Expand Up @@ -7,15 +7,20 @@ import 'package:flame/src/sprite_animation.dart';

export '../sprite_animation.dart';

/// A [Particle] which applies certain [SpriteAnimation].
class SpriteAnimationParticle extends Particle {
final SpriteAnimation animation;
final Vector2? position;
final Vector2? size;
final Anchor anchor;
final Paint? overridePaint;
final bool alignAnimationTime;

SpriteAnimationParticle({
required this.animation,
this.position,
this.size,
this.anchor = Anchor.center,
this.overridePaint,
super.lifespan,
this.alignAnimationTime = true,
Expand All @@ -35,8 +40,9 @@ class SpriteAnimationParticle extends Particle {
void render(Canvas canvas) {
animation.getSprite().render(
canvas,
position: position,
size: size,
anchor: Anchor.center,
anchor: anchor,
overridePaint: overridePaint,
);
}
Expand Down
8 changes: 7 additions & 1 deletion packages/flame/lib/src/particles/sprite_particle.dart
Expand Up @@ -7,14 +7,19 @@ import 'package:flame/src/sprite.dart';

export '../sprite.dart';

/// A [Particle] which applies certain [Sprite].
class SpriteParticle extends Particle {
final Sprite sprite;
final Vector2? position;
final Vector2? size;
final Anchor anchor;
final Paint? overridePaint;

SpriteParticle({
required this.sprite,
this.position,
this.size,
this.anchor = Anchor.center,
this.overridePaint,
super.lifespan,
});
Expand All @@ -23,8 +28,9 @@ class SpriteParticle extends Particle {
void render(Canvas canvas) {
sprite.render(
canvas,
position: position,
size: size,
anchor: Anchor.center,
anchor: anchor,
overridePaint: overridePaint,
);
}
Expand Down

0 comments on commit 181e0b5

Please sign in to comment.