【问题标题】:Libgdx: Different positions using BitmapFontLibgdx:使用 BitmapFont 的不同位置
【发布时间】:2014-03-11 20:52:22
【问题描述】:

我在(非常)简单的项目中遇到了问题。当我绘制文本时,它在 Android(Samsung Galaxy S Advance)和桌面之间显示在不同的位置(并且显然具有不同的大小)。

在我的渲染器类中,我有:

private OrthographicCamera cam;
public final int WIDTH  = 320;
public final int HEIGHT = 480;

private ShapeRenderer debugRenderer = new ShapeRenderer();
private SpriteBatch batch = new SpriteBatch();
private BitmapFont font;

在我的构造函数中:

MyClass(){
    this.cam = new OrthographicCamera(WIDTH, HEIGHT);
    this.cam.position.set(WIDTH/2, HEIGHT/2, 0);
    this.cam.update();
    font = new BitmapFont(Gdx.files.internal("data/fonts/font.fnt"));

    font.setColor(Color.RED);
}

最后是渲染函数:

public void render() {
     // For each block y use this code:
     // debugRenderer.begin(ShapeType.Filled);

     // Rectangle rect = block.getBounds();
     // debugRenderer.rect(rect.x, rect.y, rect.width, rect.height);
     // debugRenderer.end();

     // And then I draw my text:

     batch.begin();

     font.draw(batch, "Score: " + world.getScore(), 50,50)
     batch.end();
}

所有块尺寸都是绝对数字(与 stage.getWidth() 等任何变量无关)。

Desktop 中的结果如下:

在 Android 中,我有:

如您所见,块在屏幕上具有相同的分布(以屏幕覆盖的百分比表示),而文本则不然。它不在同一个地方开始,也没有相同的高度。

有人知道我做错了什么吗?

以防万一,块边界是:

XPos: 45 * i
YPos: 45 * j
SizeX: 32
SizeY: 32

编辑:另一个考虑因素,我使用的字体来自:https://github.com/libgdx/libgdx/tree/master/demos/superjumper

【问题讨论】:

    标签: java android libgdx


    【解决方案1】:

    this.cam.update();之后你会吗-

    batch.setProjectionMatrix(this.cam.combined);
    debugRenderer.setProjectionMatrix(this.cam.combined);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 2017-11-28
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-04
      相关资源
      最近更新 更多