我有一个白色圆圈的cells数组。每隔一个world.step左右,我想把一个随机的圆圈改成红色。我可以像这样访问和更改圆的颜色:
var n = Math.floor(Math.random()*100);
cells[n].styles.fillStyle = colors.red;这只有效一次。一旦我在Physics.util.ticker.on中调用world.step,就不会再有圆圈变成红色。下面是我的完整函数:
Physics.util.ticker.on(function(time) {
var n = Math.floor(Math.random()*100);
cells[n].styles.fillStyle = colors.red;
world.add(cells);
world.step();
});我尝试了提供的建议,得到了以下代码:
switch (newState) {
case states.cancerInterphase:
cells[n].styles.fillStyle = colors.red;
break;
case states.cancerMitosis:
cells[n].styles.fillStyle = colors.pink;
break;
case states.interphase:
cells[n].styles.fillStyle = colors.white;
break;
case states.mitosis:
cells[n].styles.fillStyle = colors.blue;
break;
}
cells[n].state.vel = new Physics.vector(speed[0], speed[1]);
cells[n].view = null;
world.add(cells);最后,step函数运行并更新页面。不幸的是,旧的圆圈的痕迹仍然留在后面。
我通过使用画布渲染器而不是pixi.js修复了这个问题。
发布于 2018-02-21 01:59:27
该库将主体的缓存图像存储在body.view中,因此为了使其刷新,您需要删除该属性,以便渲染器重新绘制图像。
var cell = cells[n];
cell.styles.fillStyle = colors.red;
cell.view = null;https://stackoverflow.com/questions/48858478
复制相似问题