Files
flame/lib/particles/paint_particle.dart
Ivan Cherepanov 0f98a8542d chore: format
fix: doc/example/particles/readme, attempt to embed webm preview
fix: doc/example/particles better sample for chaining
refactor: Particle, dropped duration support
2019-11-28 23:02:28 +03:00

42 lines
1.1 KiB
Dart

import 'dart:ui';
import 'package:flutter/foundation.dart';
import '../components/mixins/single_child_particle.dart';
import '../particle.dart';
import 'curved_particle.dart';
/// A particle which renders its child with certain [Paint]
/// Could be used for applying composite effects.
/// Be aware that any composite operation is relatively expensive, as involves
/// copying portions of GPU memory. The less pixels copied - the faster it'll be.
class PaintParticle extends CurvedParticle with SingleChildParticle {
@override
Particle child;
final Paint paint;
/// Defines Canvas layer bounds
/// for applying this particle composite effect.
/// Any child content outside this bounds will be clipped.
final Rect bounds;
PaintParticle({
@required this.child,
@required this.paint,
// Reasonably large rect for most particles
this.bounds = const Rect.fromLTRB(-50, -50, 50, 50),
double lifespan,
}) : super(
lifespan: lifespan,
);
@override
void render(Canvas canvas) {
canvas.saveLayer(bounds, paint);
super.render(canvas);
canvas.restore();
}
}