From 024dabe3c8ceabf014227b906ff992ddcd96f889 Mon Sep 17 00:00:00 2001 From: mnordine Date: Wed, 12 Oct 2016 09:48:09 -0300 Subject: [PATCH 1/7] Change StageXL dep --- pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index a5bec4b..163a635 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,7 +7,8 @@ environment: sdk: '>=1.13.0 <2.0.0' dependencies: browser: any - stagexl: '>=0.13.0 <0.14.0' + stagexl: + git: https://github.com/mnordine/StageXL transformers: - $dart2js: commandLineOptions: ["--trust-type-annotations", "--trust-primitives", "--dump-info"] From 7feac4bd64200f1f665082f79fe4d41f2dcbdf08 Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 18 May 2017 10:46:19 -0300 Subject: [PATCH 2/7] Update to use mnordine fork and dpi-fix branch --- pubspec.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 163a635..8f2fb23 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,10 @@ environment: dependencies: browser: any stagexl: - git: https://github.com/mnordine/StageXL + git: + url: https://github.com/mnordine/StageXL.git + ref: dpi-fix + transformers: - $dart2js: commandLineOptions: ["--trust-type-annotations", "--trust-primitives", "--dump-info"] From 34626f6e423cf145007914ab80c63969fcb31094 Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 18 May 2017 10:47:42 -0300 Subject: [PATCH 3/7] Don't append .git to git url --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 8f2fb23..5ee9005 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,7 @@ dependencies: browser: any stagexl: git: - url: https://github.com/mnordine/StageXL.git + url: https://github.com/mnordine/StageXL ref: dpi-fix transformers: From 5c0a685c2d7694761bfe0617de42b97be935da46 Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 18 May 2017 11:06:31 -0300 Subject: [PATCH 4/7] Use branch that works --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 5ee9005..dfb25bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: stagexl: git: url: https://github.com/mnordine/StageXL - ref: dpi-fix + ref: dpi-fix2 transformers: - $dart2js: From a4175b1b0448c2cf3141774589bacfdffaacaa08 Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 29 Jun 2017 14:08:21 -0300 Subject: [PATCH 5/7] Enable image particles --- lib/src/particle_emitter.dart | 87 ++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/lib/src/particle_emitter.dart b/lib/src/particle_emitter.dart index 607823c..87212fe 100644 --- a/lib/src/particle_emitter.dart +++ b/lib/src/particle_emitter.dart @@ -7,7 +7,7 @@ class ParticleEmitter extends DisplayObject implements Animatable { _Particle _rootParticle; _Particle _lastParticle; - RenderTexture _renderTexture = new RenderTexture(1024, 32, Color.Transparent); + RenderTexture _renderTexture; List _renderTextureQuads = new List(); int _particleCount = 0; num _frameTime = 0.0; @@ -34,6 +34,8 @@ class ParticleEmitter extends DisplayObject implements Animatable { num _endSizeVariance = 0.0; String _shape = "circle"; + BitmapData _image; + // gravity configuration num _gravityX = 0.0; num _gravityY = 0.0; @@ -69,8 +71,20 @@ class ParticleEmitter extends DisplayObject implements Animatable { _frameTime = 0.0; _particleCount = 0; - for(int i = 0; i < 32; i++) { - _renderTextureQuads.add(_renderTexture.quad.cut(new Rectangle(i * 32, 0, 32, 32))); + // Just use a single render texture quad if given an image, else generate 32 + _image = config['image']; + if (_image != null) + { + _renderTexture = _image.renderTexture; + _renderTextureQuads.add(_image.renderTextureQuad); + } + else + { + _renderTexture = new RenderTexture(1024, 32, Color.Transparent); + + for(int i = 0; i < 32; i++) { + _renderTextureQuads.add(_renderTexture.quad.cut(new Rectangle(i * 32, 0, 32, 32))); + } } updateConfig(config); @@ -81,39 +95,44 @@ class ParticleEmitter extends DisplayObject implements Animatable { void _drawParticleTexture() { - CanvasRenderingContext2D context = _renderTexture.canvas.context2D; - context.setTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); - context.globalAlpha = 1.0; - context.clearRect(0, 0, 1024, 32); - - for(int i = 0; i < 32; i++) { - - int radius = 15; - num targetX = i * 32 + 15.5; - num targetY = 15.5; - - num colorR = _startColor.red + i * (_endColor.red - _startColor.red ) / 31; - num colorG = _startColor.green + i * (_endColor.green - _startColor.green) / 31; - num colorB = _startColor.blue + i * (_endColor.blue - _startColor.blue ) / 31; - num colorA = _startColor.alpha + i * (_endColor.alpha - _startColor.alpha) / 31; - - if (i == 0) colorR = colorG = colorB = colorA = 1.0; - - int colorIntR = (255.0 * colorR).toInt(); - int colorIntG = (255.0 * colorG).toInt(); - int colorIntB = (255.0 * colorB).toInt(); + // Use Canvas2D to draw if no image given + if (_image == null) + { + CanvasRenderingContext2D context = _renderTexture.canvas.context2D; + context.setTransform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0); + context.globalAlpha = 1.0; + context.clearRect(0, 0, 1024, 32); + + for(int i = 0; i < 32; i++) { + + int radius = 15; + num targetX = i * 32 + 15.5; + num targetY = 15.5; + + num colorR = _startColor.red + i * (_endColor.red - _startColor.red ) / 31; + num colorG = _startColor.green + i * (_endColor.green - _startColor.green) / 31; + num colorB = _startColor.blue + i * (_endColor.blue - _startColor.blue ) / 31; + num colorA = _startColor.alpha + i * (_endColor.alpha - _startColor.alpha) / 31; + + if (i == 0) colorR = colorG = colorB = colorA = 1.0; + + int colorIntR = (255.0 * colorR).toInt(); + int colorIntG = (255.0 * colorG).toInt(); + int colorIntB = (255.0 * colorB).toInt(); + + var gradient = context.createRadialGradient(targetX, targetY, 0, targetX, targetY, radius); + gradient.addColorStop(0.00, "rgba($colorIntR, $colorIntG, $colorIntB, $colorA)"); + gradient.addColorStop(1.00, "rgba($colorIntR, $colorIntG, $colorIntB, 0.0)"); + context.beginPath(); + context.moveTo(targetX + radius, targetY); + context.arc(targetX, targetY, radius, 0, PI * 2.0, false); + context.fillStyle = gradient; + context.fill(); + } - var gradient = context.createRadialGradient(targetX, targetY, 0, targetX, targetY, radius); - gradient.addColorStop(0.00, "rgba($colorIntR, $colorIntG, $colorIntB, $colorA)"); - gradient.addColorStop(1.00, "rgba($colorIntR, $colorIntG, $colorIntB, 0.0)"); - context.beginPath(); - context.moveTo(targetX + radius, targetY); - context.arc(targetX, targetY, radius, 0, PI * 2.0, false); - context.fillStyle = gradient; - context.fill(); + _renderTexture.update(); } - _renderTexture.update(); } //------------------------------------------------------------------------------------------------- @@ -159,6 +178,8 @@ class ParticleEmitter extends DisplayObject implements Animatable { _endSizeVariance = _ensureNum(config["finishSizeVariance"]); _shape = config["shape"]; + _image = config['image']; + _locationXVariance = _ensureNum(config["locationVariance"]["x"]); _locationYVariance = _ensureNum(config["locationVariance"]["y"]); _speed = _ensureNum(config["speed"]); From f3f5d5db93ae64790620193fd1f1dac5ee1785d6 Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 29 Jun 2017 14:34:22 -0300 Subject: [PATCH 6/7] Revert StageXL dep --- pubspec.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index dfb25bc..97425de 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,11 +7,8 @@ environment: sdk: '>=1.13.0 <2.0.0' dependencies: browser: any - stagexl: - git: - url: https://github.com/mnordine/StageXL - ref: dpi-fix2 - + stagexl: '>=0.13.0 <0.14.0' + transformers: - $dart2js: commandLineOptions: ["--trust-type-annotations", "--trust-primitives", "--dump-info"] From d9a1b63383b1eb1d20cbe2fe8f839b75e8553aba Mon Sep 17 00:00:00 2001 From: Mark Nordine Date: Thu, 29 Jun 2017 14:35:00 -0300 Subject: [PATCH 7/7] Remove space --- pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 97425de..a5bec4b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,7 +8,6 @@ environment: dependencies: browser: any stagexl: '>=0.13.0 <0.14.0' - transformers: - $dart2js: commandLineOptions: ["--trust-type-annotations", "--trust-primitives", "--dump-info"]