2013-07-25 14 views
4

libgdx를 사용하여 디버깅 할 줄을 그려보고 싶지만 실패했습니다. 이것은 내가libgdx를 사용하여 선을 그리는 방법은 무엇입니까?

shapeDebugger.setProjectionMatrix이 (camera.combined) 라인에서 오류가 내 코드

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(); 
    } 
} 

이다; 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(); 

화면 크기를 조정하려고하면 화면이 중앙으로 업데이트되지 않고 오른쪽으로 멀리 이동합니다.

+0

어떤 오류가 발생 했습니까? 실행 시간인가, 컴파일 타임인가? –

답변

5

ShapeRenderer의 개체를 만들지 않았기 때문에 nullpointerException이 있어야합니다. 생성자에이 행을 삽입하십시오.

shapeDebugger=new ShapeRenderer(); 
+0

대단히 감사합니다. – kifcaliph

+0

문제가 있습니다. 크기를 조정하려면 – kifcaliph

+0

에 센터를 그리는 것이 좋습니다. bs 귀하는 Gdx.graphics.getWidth() 및 Gdx.graphics.getHeight()를 사용했습니다. 당신의 절두체와 절두체를 대신 사용하십시오. 당신의 문제는 해결 될 것입니다. – Pranav008

3

Shaperender를 SpriteBatch로 중첩하면 문제가 발생할 수 있습니다.

확인하십시오. link.

+0

고맙습니다. 나는이 문제를 주된 문제로 삼고 싶습니다. 내 텍스처는 예상대로 중심에 가지 않습니다. – kifcaliph

1

내 대답은 너에게 너무 늦을 지 모르지만 사람들에게는 같은 위치 결정 문제가 어떻게 발생하는지.

크기 변경 후의 위치에 대한 두 번째 질문은 뷰포트가 변경되지 않았기 때문입니다. Aldo 창 크기가 변경되었습니다. 응용 프로그램이 동일한 픽셀 크기를 사용하여 함수를 생성 할 때 설정했습니다. camera.setToOrtho

크기를 변경하면보기 포트가 업데이트됩니다!

//----------------------------------------------------------------- 
@Override 
public void resize (int width, int height) { 
    camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
    camera.update();   
} 
관련 문제