我想繪製一些線使用libgdx進行調試,但我失敗了。這是我的代碼如何使用libgdx繪製一條線?
public class MainMenu extends Screen implements InputProcessor {
private OrthographicCamera camera;
SpriteBatch myBatch;
ShapeRenderer shapeDebugger;
public MainMenu(Game game) {
super(game);
camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.update();}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
myBatch.begin();
stage.draw();
Gdx.gl10.glLineWidth(10);
shapeDebugger.setProjectionMatrix(camera.combined);
shapeDebugger.begin(ShapeType.Line);
shapeDebugger.setColor(1, 1, 1, 1);
shapeDebugger.line(2, 2, 5, 5);
myBatch.end();
}
}
我從線錯誤
shapeDebugger.setProjectionMatrix(camera.combined);
@ Pranav008
非常感謝你。我沒想到我需要發起它。但我有一個真正的問題。我畫這條線到遊戲畫面的中心。
Gdx.gl10.glLineWidth(2);
shapeDebugger.setProjectionMatrix(camera.combined);
shapeDebugger.begin(ShapeType.Line);
shapeDebugger.setColor(1, 1, 1, 1);
shapeDebugger.line(Gdx.graphics.getWidth()/2, 0,Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight());
shapeDebugger.end();
當我嘗試調整屏幕大小時,它沒有更新到中心,它遠離右邊。
你得到了什麼錯誤?它是運行時還是編譯時? –