Skip to content

Commit

Permalink
fix: [#2437] Position particles per the parent transform
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Aug 6, 2022
1 parent fa65eb8 commit 67eb50c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
13 changes: 13 additions & 0 deletions sandbox/tests/emitter/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emitter</title>
</head>
<body>
<script src="../../lib/excalibur.js"></script>
<script src="./index.js"></script>
</body>
</html>
43 changes: 43 additions & 0 deletions sandbox/tests/emitter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

var game = new ex.Engine({
width: 400,
height: 400
});

var actor = new ex.Actor({
anchor: ex.vec(0.5, 0.5),
pos: game.screen.center,
color: ex.Color.Red,
radius: 5,
});

var emitter = new ex.ParticleEmitter({
width: 10,
height: 10,
emitterType: ex.EmitterType.Rectangle,
radius: 5,
minVel: 100,
maxVel: 200,
minAngle: 5.1,
maxAngle: 6.2,
emitRate: 300,
opacity: 0.5,
fadeFlag: true,
particleLife: 1000,
maxSize: 10,
minSize: 1,
startSize: 5,
endSize: 100,
acceleration: ex.vec(10, 80),
beginColor: ex.Color.Chartreuse,
endColor: ex.Color.Magenta
});
emitter.isEmitting = true;

game.start();
game.add(actor);

actor.angularVelocity = 2;

// doesn't work
actor.addChild(emitter);
2 changes: 1 addition & 1 deletion src/engine/Particles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class ParticleImpl extends Entity {
this.endColor = endColor || this.endColor.clone();
this.beginColor = beginColor || this.beginColor.clone();
this._currentColor = this.beginColor.clone();
this.position = (position || this.position).add(this.emitter.pos);
this.position = (position || this.position).add(this.emitter.transform.globalPos);
this.velocity = velocity || this.velocity;
this.acceleration = acceleration || this.acceleration;
this._rRate = (this.endColor.r - this.beginColor.r) / this.life;
Expand Down

0 comments on commit 67eb50c

Please sign in to comment.