Skip to content

Bug report: Particles always render as black in Pixi renderer #116

Description

@BohdanHorlach

When using Proton with Pixi 5, particles rendered via PixiRenderer default circle (no texture/body) are always black, regardless of configured color settings.

Environment

  • PixiJS: ^5.3.12
  • Proton Engine: ^7.1.5

Steps to Reproduce

  1. Create a particle emitter using Proton
  2. Use Pixi renderer (in the API has the corresponding name - PixiRenderer)
  3. Do not assign a texture or custom Body
  4. Configure particle color (any value)
  5. Render particles

Expected Behavior

  • Particles should render using the configured color.

Actual Behavior

  • All particles render as black circles, regardless of the specified color.

Investigation
While debugging, I overrode the createCircle method to inspect how the color is passed.

It appears that:
Particle color is stored in HEX format
However, when passed to Graphics.beginFill, it is used as a string instead of a number
This results in Pixi rendering the color incorrectly (defaulting to black)

Workaround
Manually converting the color before passing it to beginFill resolves the issue:

const color = ColorUtil.getHex16FromParticle(particle);

After applying this conversion, particles render with the correct color.

Possible Cause
This may be related to compatibility with older versions of Pixi, where PIXI.Graphics.beginFill expects a numeric HEX value rather than a string.

Additional Notes
Issue occurs specifically when no texture/body is assigned (default circle rendering path)
Custom rendering paths may not be affected

Additional Context (with workaround example)

  • ParticleSystem.ts (adapter for my game):
import Proton, { ColorUtil, Emitter, PixiRenderer } from "proton-engine";
import IUpdatable from "./IUpdatable";
import { Container, Graphics } from "pixi.js";

export default class ParticleSystem implements IUpdatable {
  private _proton: Proton;
  private _renderer: PixiRenderer;

  constructor(stage: Container) {
    this._proton = new Proton();
    this._renderer = new PixiRenderer(stage);
    this._renderer.setColor = true;
    this._renderer.color = true;

    this._renderer.createCircle = (particle) => {
      const graphics = new Graphics();

      const color = ColorUtil.getHex16FromParticle(particle);

      graphics.beginFill(color);
      graphics.drawCircle(0, 0, particle.radius);
      graphics.endFill();

      return graphics;
    };

    this._proton.addRenderer(this._renderer);
  }

  public addParticle(emitter: Emitter): void {
    this._proton.addEmitter(emitter);
  }

  public update(): void {
    this._proton.update();
  }
}
  • Confetti.ts:
import { Container } from "pixi.js";
import {
  Alpha,
  Color,
  Emitter,
  Gravity,
  Life,
  Mass,
  Radius,
  Rate,
  Rotate,
  Span,
  Velocity,
} from "proton-engine";
import ParticleSystem from "../../../core/ParticleSystem";

export default class Confetti {
  private _emitter: Emitter;
  private _container: Container;

  constructor(stage: Container, particleSystem: ParticleSystem) {
    this._container = new Container();
    stage.addChild(this._container);

    this._emitter = this.createEmitter();

    particleSystem.addParticle(this._emitter);
  }

  private createEmitter(): Emitter {
    const emitter = new Emitter({});

    emitter.rate = new Rate(new Span(20, 40), new Span(0.05, 0.1));
    emitter.addInitialize(new Mass(1));
    emitter.addInitialize(new Radius(10));
    emitter.addInitialize(new Life(2, 4));
    emitter.addInitialize(new Velocity(new Span(1, 30), new Span(-45, 45), "polar"));

    emitter.addBehaviour(new Gravity(9.81));
    emitter.addBehaviour(new Rotate(0, 360));
    emitter.addBehaviour(new Color(["#ee00ee", "#00ee00", "#0000ee", "#ee0000"]));
    emitter.addBehaviour(new Alpha(1, 0));

    return emitter;
  }

  public emit(x: number, y: number) {
    this._emitter.p.x = x;
    this._emitter.p.y = y;

    this._emitter.emit("once");
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions