Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PixiPlugin: Error with animating fillColor with PixiJS v8 #580

Open
matt-bp opened this issue Apr 11, 2024 · 0 comments
Open

PixiPlugin: Error with animating fillColor with PixiJS v8 #580

matt-bp opened this issue Apr 11, 2024 · 0 comments

Comments

@matt-bp
Copy link

matt-bp commented Apr 11, 2024

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});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant