【发布时间】:2018-03-22 07:47:53
【问题描述】:
我有一个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 解决了这个问题。
【问题讨论】:
标签: javascript colors physicsjs