我有cells
一系列白色圆圈。每隔一段时间world.step
,我想将一个随机圆圈更改为红色。我可以像这样访问和更改圆圈的颜色:
var n = Math.floor(Math.random()*100);
cells[n].styles.fillStyle = colors.red;
这工作一次。一旦我打电话world.step
给Physics.util.ticker.on
,就没有更多的圆圈变红了。这是我的完整功能:
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 解决了这个问题。