Estoy tratando de hacer que un objeto cuadrado simple parpadee en verde, azul y rojo según diferentes condiciones. Entiendo que no hay una forma directa de cambiar el color de un objeto Graphics en PixiJS. Actualmente, creo tres objetos gráficos que son idénticos excepto por los colores. Al superponer estos objetos y ajustar la visibilidad, puedo lograr la animación intermitente.
Me preguntaba si hay una mejor manera de "cambiar" el color en lugar de engañarlo con visibilidad.
Mi código actual:
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;Podrías crear un círculo blanco y cambiar su tinte.
const circle = new PIXI.Graphics(); circle.beginFill(0xffffff); circle.drawCircle(0, 0, 100); circle.endFill(); circle.tint = 0xff0000;