【发布时间】:2019-12-03 09:53:19
【问题描述】:
我试图在鼠标悬停或鼠标悬停时更改 alpha 和颜色,但显示没有改变。
当我使用 Text 类时,它起作用了。我将样式从普通更改为粗体,如下所示:
class Leaf extends PIXI.Text{
...
this.interactive = true;
this.on('mouseover', function () {
this.style.fontWeight = 'bold';
});
}
然后我尝试更改视图的线条/链接/边缘的颜色,但它不起作用:
class TreeEdge extends Graphics{
constructor(d){
super();
this.data = d;
let p0 = project(d.source.x, d.source.y);
let p1 = project(d.target.x, d.target.y);
this.lineStyle(1, d.target.color, 1);
this.moveTo(p0[0], p0[1]);
this.lineTo(p1[0], p1[1]);
this.endFill();
this.hitArea = this.getBounds();
this.interactive = true;
this.on('mouseover', function () {
this.alpha = 1;
});
}
}
我试过this.lineAlpha、this.alpha、this.GraphicsData[0].lineAlpha...this.clear() 和this.dirty++。没有什么变化。我也尝试使用this.color 和this.lineStyle(1, node.color, 1); 更改颜色。
看来我需要更新渲染什么的。 通过用户交互更新图形元素的最佳方法是什么?
我正在使用 pixi.js - v4.7.3
像这样启动我的应用程序:
var app = new PIXI.Application(width, height, {
backgroundColor: 0xffffff,
antialias: true,
transparent: false,
resolution: 1
});
【问题讨论】:
标签: javascript graphics pixi.js