【问题标题】:PixiJS what's the best way to change a Graphics object's colour?PixiJS 更改图形对象颜色的最佳方法是什么?
【发布时间】:2021-12-31 19:54:45
【问题描述】:

我试图让一个简单的方形对象根据不同的条件闪烁绿色、蓝色和红色。我知道在 PixiJS 中没有直接的方法来更改 Graphics 对象的颜色。目前,我创建了三个相同的图形对象,除了颜色。通过重叠这些对象并调整可见性,我能够完成闪烁的动画。

我想知道是否有更好的方法来“改变”颜色而不是用可见性欺骗它。

我当前的代码:

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;

【问题讨论】:

    标签: javascript pixi.js


    【解决方案1】:

    您可以创建一个白色圆圈并更改其色调。

    const circle = new PIXI.Graphics();
    circle.beginFill(0xffffff);
    circle.drawCircle(0, 0, 100);
    circle.endFill();
    
    circle.tint = 0xff0000;
    

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-06
      • 2011-09-14
      • 2011-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多