mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
feat: docs, adde particles docs
fix: doc/examples/particles, added web to .gitignore feat: doc/examples/particles, added more examples, refactor: Particle does not extend Component refactor: Particle subclasses in separate folder refactor: ParticleComponent is now simple container fix: SingleChildParticle, asserts for child existing feat: AnimationParticle for Flame Animation feat: ComponentParticle for Flame Component feat: SpriteParticle for Flame Sprite
This commit is contained in:
43
lib/particles/paint_particle.dart
Normal file
43
lib/particles/paint_particle.dart
Normal file
@ -0,0 +1,43 @@
|
||||
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,
|
||||
Duration duration,
|
||||
}) : super(
|
||||
lifespan: lifespan,
|
||||
duration: duration,
|
||||
);
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
canvas.saveLayer(bounds, paint);
|
||||
super.render(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user