从box2d.world.getParticlePositionBuffer()中删除粒子

时间:2016-06-08 17:54:37

标签: processing box2d particle-system

如何在屏幕离开时从box2d.world中删除粒子?

目前,我的代码来自Nature of Code - LiquidFunTest示例:

Vec2[] positionBuffer = box2d.world.getParticlePositionBuffer();
if (positionBuffer != null) {
  for (int i = 0; i < positionBuffer.length; i++) {
    Vec2 pos = box2d.coordWorldToPixels(positionBuffer[i]);
    pg.stroke(255);
    pg.strokeWeight(3);
    pg.point(pos.x, pos.y);
  }
}

我已将代码更改为:

Vec2[] positionBuffer = box2d.world.getParticlePositionBuffer();
if (positionBuffer != null) {

  for (int i = 0; i < positionBuffer.length; i++) {
    Vec2 pos = box2d.coordWorldToPixels(positionBuffer[i]);
    if(pos.y > height){
      box2d.world.destroyParticle(i);
    } else {
      pg.stroke(255);
      pg.strokeWeight(3);
      pg.point(pos.x, pos.y);
    }
  }
}

destroyParticle()方法与getParticlePositionBuffer()

的索引不同

0 个答案:

没有答案