Próbuję zmusić prosty kwadratowy obiekt migać na zielono, niebiesko i czerwono, w zależności od różnych warunków. Rozumiem, że w PixiJS nie ma bezpośredniego sposobu, aby zmienić kolor obiektu graficznego. Obecnie tworzę trzy graficznych obiektu, które są identyczne, za wyjątkiem kolorów. Pokrywać te obiekty i regulując widoczność, mogę wykonać animację migania.
Zastanawiałem się, czy istnieje lepszy sposób "zmienić" kolor zamiast oszukiwać jego widoczność.
Mój obecny kod:
let square_red = new PIXI.Graphics();
square.beginFill(red, opacity);
square.lineStyle(lineStyle);
square.drawRect(0, 0, width, height);
square.position.set(x, y);
let square_green = new PIXI.Graphics();
square.beginFill(green, opacity);
square.lineStyle(lineStyle);
square.drawRect(0, 0, width, height);
square.position.set(x, y);
let square_blue = new PIXI.Graphics();
square.beginFill(blue, opacity);
square.lineStyle(lineStyle);
square.drawRect(0, 0, width, height);
square.position.set(x, y);
square_red.visible = true;
square_green.visible = false;
square_blue.visible = false;