Skip to content

Commit 7313573

Browse files
committed
The ParticleEmitterManager now has the Transform component. This means you can now set the position, rotation or scale of the Emitter Manager, and it will influence every Emitter it is rendering. The Managers transform is mixed with that of the Camera. This works in both Canvas and WebGL.
1 parent c3cc431 commit 7313573

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The process of managing scissors in the WebGLRenderer has been completely rewrit
4848
* `TextureManager.getBase64` is a new method that will take a texture frame key and return a base64 encoded version of the frame. You can also provide the image type and encoder options.
4949
* Global Plugins now have a new optional `data` object, the contents of which are passed to the plugins `init` method. This allows users to pass data directly into a plugin when added in the config: `{ key: 'BankPlugin', plugin: BankPluginV3, start: true, data: { gold: 5000 } }` or when adding a plugin via the `install` method (thanks @samme)
5050
* You can now play animations in reverse! Use the new `Sprite.anims.playReverse` method to play a pre-defined animation in reverse from its starting frame. Or call `Sprite.anims.reverse` to immediately reverse the flow of an already running animation. Animations running in reverse still count towards the repeat total and respect the yoyo flag (thanks @khaleb85)
51+
* The `ParticleEmitterManager` now has the Transform component. This means you can now set the position, rotation or scale of the Emitter Manager, and it will influence every Emitter it is rendering. The Managers transform is mixed with that of the Camera. This works in both Canvas and WebGL.
5152

5253
### Updates
5354

src/gameobjects/particles/ParticleEmitterManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var Render = require('./ParticleManagerRender');
2424
*
2525
* @extends Phaser.GameObjects.Components.Depth
2626
* @extends Phaser.GameObjects.Components.Pipeline
27+
* @extends Phaser.GameObjects.Components.Transform
2728
* @extends Phaser.GameObjects.Components.Visible
2829
*
2930
* @param {Phaser.Scene} scene - The Scene to which this Emitter Manager belongs.
@@ -38,6 +39,7 @@ var ParticleEmitterManager = new Class({
3839
Mixins: [
3940
Components.Depth,
4041
Components.Pipeline,
42+
Components.Transform,
4143
Components.Visible,
4244
Render
4345
],

src/gameobjects/particles/ParticleManagerCanvasRenderer.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpol
2929
return;
3030
}
3131

32+
var camMatrix = renderer._tempMatrix1.copyFrom(camera.matrix);
33+
var managerMatrix = renderer._tempMatrix2.applyITRS(emitterManager.x, emitterManager.y, emitterManager.rotation, emitterManager.scaleX, emitterManager.scaleY);
34+
35+
camMatrix.multiply(managerMatrix);
36+
3237
var ctx = renderer.currentContext;
38+
var matrix = camMatrix.matrix;
3339

3440
ctx.save();
3541

42+
ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
43+
3644
if (parentMatrix !== undefined)
3745
{
38-
var matrix = parentMatrix.matrix;
46+
matrix = parentMatrix.matrix;
3947

4048
ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
4149
}

src/gameobjects/particles/ParticleManagerWebGLRenderer.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7+
var Utils = require('../../renderer/webgl/Utils');
8+
79
/**
810
* Renders this Game Object with the WebGL Renderer to the given Camera.
911
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@@ -34,14 +36,18 @@ var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpola
3436
var camMatrix = pipeline._tempMatrix1.copyFrom(camera.matrix);
3537
var calcMatrix = pipeline._tempMatrix2;
3638
var particleMatrix = pipeline._tempMatrix3;
39+
var managerMatrix = pipeline._tempMatrix4.applyITRS(emitterManager.x, emitterManager.y, emitterManager.rotation, emitterManager.scaleX, emitterManager.scaleY);
40+
41+
camMatrix.multiply(managerMatrix);
3742

3843
renderer.setPipeline(pipeline);
3944

4045
var roundPixels = camera.roundPixels;
4146
var texture = emitterManager.defaultFrame.glTexture;
47+
var getTint = Utils.getTintAppendFloatAlphaAndSwap;
4248

4349
pipeline.setTexture2D(texture, 0);
44-
50+
4551
for (var e = 0; e < emittersLength; e++)
4652
{
4753
var emitter = emitters[e];
@@ -71,19 +77,20 @@ var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpola
7177
pipeline.setTexture2D(texture, 0);
7278
}
7379

74-
var tintEffect = false;
80+
var tintEffect = 0;
7581

7682
for (var i = 0; i < particleCount; i++)
7783
{
7884
var particle = particles[i];
7985

80-
if (particle.alpha <= 0)
86+
var alpha = particle.alpha * camera.alpha;
87+
88+
if (alpha <= 0)
8189
{
8290
continue;
8391
}
8492

8593
var frame = particle.frame;
86-
var color = particle.color;
8794

8895
var x = -(frame.halfWidth);
8996
var y = -(frame.halfHeight);
@@ -124,7 +131,9 @@ var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpola
124131
ty3 |= 0;
125132
}
126133

127-
if (pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, color, color, color, color, tintEffect))
134+
var tint = getTint(particle.tint, alpha);
135+
136+
if (pipeline.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, tintEffect))
128137
{
129138
pipeline.setTexture2D(texture, 0);
130139
}

0 commit comments

Comments
 (0)