有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

javascript使用摄像头LibGDX移动位图字体

嗨,我是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();
}

共 (1) 个答案

  1. # 1 楼答案

    它抖动的原因是,默认情况下,文本位置被舍入为整数位置。可以在每个文本对象上设置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();
    }