Line data Source code
1 : import 'dart:ui'; 2 : 3 : import '../../particles/particle.dart'; 4 : 5 : /// Implements basic behavior for nesting [Particle] instances 6 : /// into each other. 7 : /// 8 : /// ```dart 9 : /// class BehaviorParticle extends Particle with SingleChildParticle { 10 : /// Particle child; 11 : /// 12 : /// BehaviorParticle({ 13 : /// @required this.child 14 : /// }); 15 : /// 16 : /// @override 17 : /// update(double dt) { 18 : /// // Will ensure that child [Particle] is properly updated 19 : /// super.update(dt); 20 : /// 21 : /// // ... Custom behavior 22 : /// } 23 : /// } 24 : /// ``` 25 : mixin SingleChildParticle on Particle { 26 : late Particle child; 27 : 28 0 : @override 29 : void setLifespan(double lifespan) { 30 0 : super.setLifespan(lifespan); 31 0 : child.setLifespan(lifespan); 32 : } 33 : 34 0 : @override 35 : void render(Canvas c) { 36 0 : child.render(c); 37 : } 38 : 39 0 : @override 40 : void update(double dt) { 41 0 : super.update(dt); 42 0 : child.update(dt); 43 : } 44 : }