如何在屏幕离开时从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()