如何在 Libgdx Box2d 中保持 body 不渲染?
How do I keep a body unrendered in Libgdx Box2d?
我在任何地方都找不到答案,我开始怀疑这是否可能。如何在 LIbgdx "Invisble" 中保留 body?这样它将与所有事物保持交互并像常规 body 一样运行,但不会被渲染
您可以创建自己的 Box2dDebugRenderer 并覆盖 renderBody
方法。
class MyBox2dRenderer extends Box2DDebugRenderer {
private ArrayList<Body> notRenderingBodies; // array of vodies that you dont want to render
public MyBox2dRenderer(ArrayList<Body> notRenderingBodies) {
super();
this.notRenderingBodies = notRenderingBodies;
}
@Override
protected void renderBody(Body body) {
for (Body b : notRenderingBodies) { // loop through all bodies in array
if (b == body){ // if given body equals by reference to one from list than return
return;
}
}
super.renderBody(body);
}
public ArrayList<Body> getNotDenderingBodies() {
return notRenderingBodies;
}
public void setNotDenderingBodies(ArrayList<Body> notDenderingBodies) {
this.notRenderingBodies = notDenderingBodies;
}
}
我在任何地方都找不到答案,我开始怀疑这是否可能。如何在 LIbgdx "Invisble" 中保留 body?这样它将与所有事物保持交互并像常规 body 一样运行,但不会被渲染
您可以创建自己的 Box2dDebugRenderer 并覆盖 renderBody
方法。
class MyBox2dRenderer extends Box2DDebugRenderer {
private ArrayList<Body> notRenderingBodies; // array of vodies that you dont want to render
public MyBox2dRenderer(ArrayList<Body> notRenderingBodies) {
super();
this.notRenderingBodies = notRenderingBodies;
}
@Override
protected void renderBody(Body body) {
for (Body b : notRenderingBodies) { // loop through all bodies in array
if (b == body){ // if given body equals by reference to one from list than return
return;
}
}
super.renderBody(body);
}
public ArrayList<Body> getNotDenderingBodies() {
return notRenderingBodies;
}
public void setNotDenderingBodies(ArrayList<Body> notDenderingBodies) {
this.notRenderingBodies = notDenderingBodies;
}
}