Skip to content

Commit

Permalink
fix: ParticleEmitter errant draw when using particleSprite
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Feb 9, 2024
1 parent 3377b41 commit 5943a8f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Fixed issue where particles would have an errant draw if using a particle sprite
- Fixed issue where a null/undefined graphics group member graphic would cause a crash, now logs a warning.
- Fixed issue where Actor built in components could not be extended because of the way the Actor based type was built.
- Actors now use instance properties for built-ins instead of getters
Expand Down
35 changes: 18 additions & 17 deletions src/engine/Particles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { CollisionType } from './Collision/CollisionType';
import { TransformComponent } from './EntityComponentSystem/Components/TransformComponent';
import { GraphicsComponent } from './Graphics/GraphicsComponent';
import { Entity } from './EntityComponentSystem/Entity';
import { Sprite } from './Graphics/Sprite';
import { BoundingBox } from './Collision/BoundingBox';
import { clamp, randomInRange } from './Math/util';
import { Graphic } from './Graphics';

/**
* An enum that represents the types of emitter nozzles
Expand Down Expand Up @@ -56,7 +56,7 @@ export class ParticleImpl extends Entity {

public emitter: ParticleEmitter = null;
public particleSize: number = 5;
public particleSprite: Sprite = null;
public particleSprite: Graphic = null;

public startSize: number;
public endSize: number;
Expand All @@ -79,7 +79,8 @@ export class ParticleImpl extends Entity {
velocity?: Vector,
acceleration?: Vector,
startSize?: number,
endSize?: number
endSize?: number,
particleSprite?: Graphic
) {
super();
let emitter = emitterOrConfig;
Expand All @@ -95,13 +96,15 @@ export class ParticleImpl extends Entity {
acceleration = config.acceleration;
startSize = config.startSize;
endSize = config.endSize;
particleSprite = config.particleSprite;
}
this.emitter = <ParticleEmitter>emitter;
this.life = life || this.life;
this.opacity = opacity || this.opacity;
this.endColor = endColor || this.endColor.clone();
this.beginColor = beginColor || this.beginColor.clone();
this._currentColor = this.beginColor.clone();
this.particleSprite = particleSprite;

if (this.emitter.particleTransform === ParticleTransform.Global) {
const globalPos = this.emitter.transform.globalPos;
Expand Down Expand Up @@ -207,7 +210,7 @@ export interface ParticleArgs extends Partial<ParticleImpl> {
particleRotationalVelocity?: number;
currentRotation?: number;
particleSize?: number;
particleSprite?: Sprite;
particleSprite?: Graphic;
}

/**
Expand All @@ -225,7 +228,8 @@ export class Particle extends Configurable(ParticleImpl) {
velocity?: Vector,
acceleration?: Vector,
startSize?: number,
endSize?: number
endSize?: number,
particleSprite?: Graphic
);
constructor(
emitterOrConfig: ParticleEmitter | ParticleArgs,
Expand All @@ -237,9 +241,10 @@ export class Particle extends Configurable(ParticleImpl) {
velocity?: Vector,
acceleration?: Vector,
startSize?: number,
endSize?: number
endSize?: number,
particleSprite?: Graphic
) {
super(emitterOrConfig, life, opacity, beginColor, endColor, position, velocity, acceleration, startSize, endSize);
super(emitterOrConfig, life, opacity, beginColor, endColor, position, velocity, acceleration, startSize, endSize, particleSprite);
}
}

Expand Down Expand Up @@ -288,7 +293,7 @@ export interface ParticleEmitterArgs {
maxSize?: number;
beginColor?: Color;
endColor?: Color;
particleSprite?: Sprite;
particleSprite?: Graphic;
emitterType?: EmitterType;
radius?: number;
particleRotationalVelocity?: number;
Expand Down Expand Up @@ -408,15 +413,15 @@ export class ParticleEmitter extends Actor {
*/
public endColor: Color = Color.White;

private _sprite: Sprite = null;
private _sprite: Graphic = null;
/**
* Gets or sets the sprite that a particle should use
*/
public get particleSprite(): Sprite {
public get particleSprite(): Graphic {
return this._sprite;
}

public set particleSprite(val: Sprite) {
public set particleSprite(val: Graphic) {
if (val) {
this._sprite = val;
}
Expand Down Expand Up @@ -576,15 +581,11 @@ export class ParticleEmitter extends Actor {
new Vector(dx, dy),
this.acceleration,
this.startSize,
this.endSize
this.endSize,
this.particleSprite
);
p.fadeFlag = this.fadeFlag;
p.particleSize = size;
if (this.particleSprite) {
p.particleSprite = this.particleSprite;
p.graphics.opacity = this.opacity;
p.graphics.use(this._sprite);
}
p.particleRotationalVelocity = this.particleRotationalVelocity;
if (this.randomRotation) {
p.currentRotation = randomInRange(0, Math.PI * 2, this.random);
Expand Down

0 comments on commit 5943a8f

Please sign in to comment.