Skip to content

PixiPlugin: Error with animating fillColor with PixiJS v8 #580

Description

@matt-bp

Problem

In PixiJS V8, I get an error when trying to animate the fill color of a PIXI.Graphics using the PixiPlugin.

Example

https://codepen.io/matt-bp/pen/XWQYgVK

Uncomment the second gsap.to to see the error.

My workaround (also for anyone else experiencing this issue)

I'm currently working around this error by creating a color object with three properties (r, g, b), using gsap to animate each color channel individually. I'm then using the onUpdate property in the gsap.to options to update the graphic's fill color and call graphics.fill() to update the color.

// ... Other pixijs setup

const color = {r: 0, g: 0, b: 255};
const target = {r: 100, g: 10, b: 255};

const graphics = new PIXI.Graphics();
graphics.rect(0, 0, 100, 100);
graphics.fillStyle.color = rgbToHex(color.r, color.g, color.b);
graphics.fill();
app.stage.addChild(graphics);

const updateFill = () => {
  color.r = Math.floor(color.r);
  color.g = Math.floor(color.g);
  color.b = Math.floor(color.b);

  graphics.fillStyle.color = rgbToHex(color.r, color.g, color.b);
  graphics.fill();
};

gsap.to(color, {r: target.r, g: target.g, b: target.b, duration: 2, onUpdate: updateFill, yoyo: true, repeat: -1});

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions