gpt4 book ai didi

java - libGDX FitViewport 不适用于 Android

转载 作者:搜寻专家 更新时间:2023-11-01 07:55:36 24 4
gpt4 key购买 nike

我有这种方法可以在 Windows 桌面上按预期工作和扩展:

public class MyGdxGame extends ApplicationAdapter {
SpriteBatch m_batch;
FitViewport m_viewport;
OrthographicCamera m_camera;

private Texture img;
private BitmapFont m_font;


@Override
public void create() {
Gdx.app.setLogLevel(Application.LOG_NONE);

m_batch = new SpriteBatch();

m_camera = new OrthographicCamera();
m_camera.position.set(640 / 2f, 400 / 2f, 0);
m_camera.update();
m_viewport = new FitViewport(640, 400, m_camera);

img = new Texture("badlogic.jpg");

m_font = new BitmapFont();
}

@Override
public void render() {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
m_batch.begin();
m_font.draw(m_batch, "X000000000000000000000000000000000000000000000000000000000000000000000000000000X", 0, m_camera.viewportHeight);
m_batch.draw(img, 0, 0);
m_batch.end();
}

@Override
public void resize(int width, int height) {
m_viewport.update(width, height);
}
}

初始窗口大小: 01

更大的窗口尺寸 02

但如果我部署到 Android(在本例中为 Nexus 7 2013),它似乎无法正确扩展: 03

为什么不起作用?如何解决?

最佳答案

您忘记在 Sprite 批处理中使用相机。调用

spriteBatch.setProjectionMatrix(viewport.getCamera().combined);

spriteBatch.begin(); 之前。

关于java - libGDX FitViewport 不适用于 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28170589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com