我不知道爲什麼ShapeRenderer對象不在屏幕上繪製圓。我嘗試修改代碼以包含建議,例如將我的shaperenderer對象的投影矩陣和變換矩陣更改爲批處理對象,甚至在shaperenderer.begin()之前添加batch.end()。這裏是我的代碼:ShapeRenderer LibGdx不工作
public void draw (Batch batch, float parentAlpha){
super.draw(batch, parentAlpha);
batch.end();
shapeRend.setProjectionMatrix(batch.getProjectionMatrix());
shapeRend.setTransformMatrix(batch.getTransformMatrix());
float x = body.getWorldCenter().x;
float y = body.getWorldCenter().y;
shapeRend.translate(x, y, 0);
shapeRend.begin(ShapeType.Filled);
shapeRend.setColor(Color.RED);
shapeRend.circle(0, 0, Constants.PLAYER_RADIUS);
shapeRend.end();
batch.begin();
}
實在是沒有其他的代碼,我可以提供比Contants.player_radius = 0.2,不應該有所作爲等。我有我的世界渲染器(Box2D物理),這是可見的,但shaperenderer圈不存在。最初我沒有把翻譯功能,直接把x和y放到shapeRend.circle(x,y,r)方法調用中,但我只是測試了不同的方法。任何的意見都將會有幫助。謝謝。
我相信,如果你沒有設置任何東西,shaperenderer使用像素座標。我建議首先進行測試,然後在知道這個方法有效時向其添加轉換。 –