Files
flame/lib/components/mixins/single_child_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

51 lines
919 B
Dart

import 'dart:ui';
import '../../particle.dart';
/// Implements basic behavior for nesting [Particle] instances
/// into each other.
///
/// ```dart
/// class BehaviorParticle extends Particle with SingleChildParticle {
/// Particle child;
///
/// BehaviorParticle({
/// @required this.child
/// });
///
/// @override
/// update(double dt) {
/// // Will ensure that child [Particle] is properly updated
/// super.update(dt);
///
/// // ... Custom behavior
/// }
/// }
/// ```
mixin SingleChildParticle on Particle {
Particle child;
@override
void setLifespan(double lifespan) {
assert(child != null);
super.setLifespan(lifespan);
child.setLifespan(lifespan);
}
@override
void render(Canvas c) {
assert(child != null);
child.render(c);
}
@override
void update(double t) {
assert(child != null);
super.update(t);
child.update(t);
}
}