| OLD | NEW |
| 1 part of sprites; | 1 part of sprites; |
| 2 | 2 |
| 3 class _Particle { | 3 class _Particle { |
| 4 Vector2 pos; | 4 Vector2 pos; |
| 5 Vector2 startPos; | 5 Vector2 startPos; |
| 6 | 6 |
| 7 double colorPos; | 7 double colorPos; |
| 8 double deltaColorPos; | 8 double deltaColorPos; |
| 9 | 9 |
| 10 double size; | 10 double size; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 this.numParticlesToEmit: 0, | 115 this.numParticlesToEmit: 0, |
| 116 this.autoRemoveOnFinish: true}) { | 116 this.autoRemoveOnFinish: true}) { |
| 117 _particles = new List<_Particle>(); | 117 _particles = new List<_Particle>(); |
| 118 _rand = new Math.Random(); | 118 _rand = new Math.Random(); |
| 119 _emitCounter = 0.0; | 119 _emitCounter = 0.0; |
| 120 _elapsedTime = 0.0; | 120 _elapsedTime = 0.0; |
| 121 if (gravity == null) gravity = new Vector2.zero(); | 121 if (gravity == null) gravity = new Vector2.zero(); |
| 122 if (colorSequence == null) colorSequence = new ColorSequence.fromStartAndEnd
Color(new Color(0xffffffff), new Color(0x00ffffff)); | 122 if (colorSequence == null) colorSequence = new ColorSequence.fromStartAndEnd
Color(new Color(0xffffffff), new Color(0x00ffffff)); |
| 123 } | 123 } |
| 124 | 124 |
| 125 @override |
| 125 void update(double dt) { | 126 void update(double dt) { |
| 126 | 127 |
| 127 // Create new particles | 128 // Create new particles |
| 128 double rate = 1.0 / emissionRate; | 129 double rate = 1.0 / emissionRate; |
| 129 | 130 |
| 130 if (_particles.length < maxParticles) { | 131 if (_particles.length < maxParticles) { |
| 131 _emitCounter += dt; | 132 _emitCounter += dt; |
| 132 } | 133 } |
| 133 | 134 |
| 134 while(_particles.length < maxParticles | 135 while(_particles.length < maxParticles |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 particle.deltaColorPos = 1.0 / particle.timeToLive; | 230 particle.deltaColorPos = 1.0 / particle.timeToLive; |
| 230 | 231 |
| 231 if (alphaVar != 0 || redVar != 0 || greenVar != 0 || blueVar != 0) { | 232 if (alphaVar != 0 || redVar != 0 || greenVar != 0 || blueVar != 0) { |
| 232 particle.colorSequence = new ColorSequence.copyWithVariance(colorSequence,
alphaVar, redVar, greenVar, blueVar); | 233 particle.colorSequence = new ColorSequence.copyWithVariance(colorSequence,
alphaVar, redVar, greenVar, blueVar); |
| 233 } | 234 } |
| 234 | 235 |
| 235 _particles.add(particle); | 236 _particles.add(particle); |
| 236 _numEmittedParticles++; | 237 _numEmittedParticles++; |
| 237 } | 238 } |
| 238 | 239 |
| 240 @override |
| 239 void paint(PaintingCanvas canvas) { | 241 void paint(PaintingCanvas canvas) { |
| 240 | 242 |
| 241 List<RSTransform> transforms = []; | 243 List<RSTransform> transforms = []; |
| 242 List<Rect> rects = []; | 244 List<Rect> rects = []; |
| 243 List<Color> colors = []; | 245 List<Color> colors = []; |
| 244 | 246 |
| 245 for (_Particle particle in _particles) { | 247 for (_Particle particle in _particles) { |
| 246 // Transform | 248 // Transform |
| 247 double scos; | 249 double scos; |
| 248 double ssin; | 250 double ssin; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 312 |
| 311 // TODO: Needs bindings to Skia SkRSXform | 313 // TODO: Needs bindings to Skia SkRSXform |
| 312 class RSTransform { | 314 class RSTransform { |
| 313 double scos; | 315 double scos; |
| 314 double ssin; | 316 double ssin; |
| 315 double tx; | 317 double tx; |
| 316 double ty; | 318 double ty; |
| 317 | 319 |
| 318 RSTransform(this.scos, this.ssin, this.tx, this.ty); | 320 RSTransform(this.scos, this.ssin, this.tx, this.ty); |
| 319 } | 321 } |
| OLD | NEW |