2

我试图让我的文字出现,但我无法在屏幕上显示它。我玩过这些数字几次,发现 LibGDX 将字体绘制到异常大的尺寸,但我不知道是否仍需要将字体尺寸缩小,或者是否将它们绘制到屏幕外。我已经复制了整个代码并将其粘贴在下面。

我使用 Hiero 在白色背景上制作了 256x256 的 ariel black 位图字体。

package com.me.manners;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.me.input.Input;
public class Choice implements Screen
{
private PerspectiveCamera camera;
private SpriteBatch batch;
private Texture arrowT;
private Sprite arrowS;
private BitmapFont font;
private String str1 = "Hello World!";
private Input input = new Input();
private Manners game;

public Choice(Manners game)
{
    this.game = game;
    camera = new PerspectiveCamera();
    batch = new SpriteBatch();
    font = new BitmapFont(Gdx.files.internal("data/choice/ariel.fnt"), Gdx.files.internal("data/choice/ariel.png"),false);
    Gdx.input.setInputProcessor(input);

    arrowT = new Texture(Gdx.files.internal("data/choice/arrow.png"));
    arrowT.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    arrowS = new Sprite(new TextureRegion(arrowT, 0, 0, 64, 64));
    arrowS.setSize(0.125f, 0.25f);
    arrowS.setPosition(-0.75f, 0);
}

@Override
public void dispose() {
    batch.dispose();
    arrowT.dispose();
}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    arrowS.draw(batch);
    font.setColor(1.0f,1.0f,0.0f,1.0f);
    font.setScale(0.5f,0.5f);
    font.draw(batch, str1, Gdx.graphics.getWidth()*0.5f, Gdx.graphics.getHeight()*0.5f);
    batch.end();
}
}
4

2 回答 2

1

我认为您的游戏是 2D 游戏,因此使用camera = new OrthographicCamera(viewportWidth, viewportHeight)可以解决您的问题。

于 2013-12-03T09:56:23.327 回答
1

phucvin进行了很好的观察。看来你的游戏是 2d 的,所以你应该使用OrtographicCamera。我建议您使用大数字,因为 BitmapFont 将使用其正确的像素大小进行渲染(这就是您看到非常大的字母的原因)。

camera = new OrthographicCamera(480, 320); //for example.

当然,您需要将 Sprite 尺寸更改为更大的尺寸

arrowS.setSize(100, 20); //for example

或者为精灵使用具有低视口值的第二个相机。

于 2014-01-10T09:52:22.747 回答