| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 int alphaVar; | 69 int alphaVar; |
| 70 int redVar; | 70 int redVar; |
| 71 int greenVar; | 71 int greenVar; |
| 72 int blueVar; | 72 int blueVar; |
| 73 TransferMode colorTransferMode; | 73 TransferMode colorTransferMode; |
| 74 TransferMode transferMode; | 74 TransferMode transferMode; |
| 75 | 75 |
| 76 List<_Particle> _particles; | 76 List<_Particle> _particles; |
| 77 | 77 |
| 78 double _emitCounter; | 78 double _emitCounter; |
| 79 double _elapsedTime; | 79 // double _elapsedTime; |
| 80 int _numEmittedParticles = 0; | 80 int _numEmittedParticles = 0; |
| 81 | 81 |
| 82 math.Random _rand; | 82 math.Random _rand; |
| 83 | 83 |
| 84 ParticleSystem(this.texture, | 84 ParticleSystem(this.texture, |
| 85 {this.life: 1.5, | 85 {this.life: 1.5, |
| 86 this.lifeVar: 1.0, | 86 this.lifeVar: 1.0, |
| 87 this.posVar: Point.origin, | 87 this.posVar: Point.origin, |
| 88 this.startSize: 2.5, | 88 this.startSize: 2.5, |
| 89 this.startSizeVar: 0.5, | 89 this.startSizeVar: 0.5, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 110 this.redVar: 0, | 110 this.redVar: 0, |
| 111 this.greenVar: 0, | 111 this.greenVar: 0, |
| 112 this.blueVar: 0, | 112 this.blueVar: 0, |
| 113 this.colorTransferMode: TransferMode.multiply, | 113 this.colorTransferMode: TransferMode.multiply, |
| 114 this.transferMode: TransferMode.plus, | 114 this.transferMode: TransferMode.plus, |
| 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 void update(double dt) { | 125 void update(double dt) { |
| 126 | 126 |
| 127 // Create new particles | 127 // Create new particles |
| 128 double rate = 1.0 / emissionRate; | 128 double rate = 1.0 / emissionRate; |
| 129 | 129 |
| 130 if (_particles.length < maxParticles) { | 130 if (_particles.length < maxParticles) { |
| 131 _emitCounter += dt; | 131 _emitCounter += dt; |
| 132 } | 132 } |
| 133 | 133 |
| 134 while(_particles.length < maxParticles | 134 while(_particles.length < maxParticles |
| 135 && _emitCounter > rate | 135 && _emitCounter > rate |
| 136 && (numParticlesToEmit == 0 || _numEmittedParticles < numParticlesToEmit)
) { | 136 && (numParticlesToEmit == 0 || _numEmittedParticles < numParticlesToEmit)
) { |
| 137 // Add a new particle | 137 // Add a new particle |
| 138 _addParticle(); | 138 _addParticle(); |
| 139 _emitCounter -= rate; | 139 _emitCounter -= rate; |
| 140 } | 140 } |
| 141 | 141 |
| 142 _elapsedTime += dt; | 142 // _elapsedTime += dt; |
| 143 | 143 |
| 144 // Iterate over all particles | 144 // Iterate over all particles |
| 145 for (int i = _particles.length -1; i >= 0; i--) { | 145 for (int i = _particles.length -1; i >= 0; i--) { |
| 146 _Particle particle = _particles[i]; | 146 _Particle particle = _particles[i]; |
| 147 | 147 |
| 148 // Manage life time | 148 // Manage life time |
| 149 particle.timeToLive -= dt; | 149 particle.timeToLive -= dt; |
| 150 if (particle.timeToLive <= 0) { | 150 if (particle.timeToLive <= 0) { |
| 151 _particles.removeAt(i); | 151 _particles.removeAt(i); |
| 152 continue; | 152 continue; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 310 |
| 311 // TODO: Needs bindings to Skia SkRSXform | 311 // TODO: Needs bindings to Skia SkRSXform |
| 312 class RSTransform { | 312 class RSTransform { |
| 313 double scos; | 313 double scos; |
| 314 double ssin; | 314 double ssin; |
| 315 double tx; | 315 double tx; |
| 316 double ty; | 316 double ty; |
| 317 | 317 |
| 318 RSTransform(this.scos, this.ssin, this.tx, this.ty); | 318 RSTransform(this.scos, this.ssin, this.tx, this.ty); |
| 319 } | 319 } |
| OLD | NEW |