2016-10-27 3 views
-1

안녕하세요 저는 LibGDX 초보자입니다. 저는 움직이는 카메라가 있고 카메라가 움직이는 동안 점수를 표시하고 싶습니다. 나는 이것을했지만 텍스트 (점수)는 카메라가 움직일 때 흔들린다. 이 문제를 해결하는 방법을 모르겠습니다. 내 코드는 다음과 같습니다.카메라로 BitmapFont 이동 LibGDX

public void render(SpriteBatch sb) { 
    sb.setProjectionMatrix(cam.combined); 
    sb.begin(); 
    String s = Integer.toString(SCORE); 
    String h = Integer.toString(highscore); 

    sb.draw(bg,cam.position.x - (cam.viewportWidth /2),0); 


    sb.draw(groud,groundpos1.x,groundpos1.y); 
    sb.draw(groud,groundpos2.x,groundpos2.y); 


    font.draw(sb,s,cam.position.x-font.getSpaceWidth(),cam.position.y+(cam.viewportHeight /2)-39); 
    high.draw(sb,h,cam.position.x- (cam.viewportWidth /2),cam.position.y+(cam.viewportHeight /2)-39); 
    sb.end(); 
} 

답변

0

왜곡 된 이유는 텍스트 위치가 기본적으로 정수 위치로 반올림되기 때문입니다. 이 문제를 피하려면 각 텍스트 개체에 font.setUseIntegerPositions(false)을 설정할 수 있습니다.

그러나 게임 세계의 카메라로 GUI를 움직이는 것은 실용적이지 않습니다. GUI 용으로 별도의 카메라를 만듭니다.

public void render(SpriteBatch sb) { 
    sb.setProjectionMatrix(gameCam.combined); 
    sb.begin(); 

    sb.draw(bg,gameCam.position.x - (gameCam.viewportWidth /2),0); 

    sb.draw(groud,groundpos1.x,groundpos1.y); 
    sb.draw(groud,groundpos2.x,groundpos2.y); 


    sb.setProjectionMatrix(guiCam.combined); 
    String s = Integer.toString(SCORE); 
    String h = Integer.toString(highscore); 
    font.draw(sb, s, font.getSpaceWidth(), guiCam.viewportHeight/2 - 39); 
    high.draw(sb, h, guiCam.viewportWidth /2, guiCam.viewportHeight/2 - 39); 
    sb.end(); 
} 
관련 문제