本文介绍了LibGDX文本无法在大屏幕上正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的854 x 480 LG Leon上,它可以正常显示,但是在较大的屏幕分辨率(2560 x 1440)上会发生这种情况: http://imgur.com/a/rcbJK .

On my 854 x 480 LG Leon it renders fine, but on a larger screen resolution (2560 x 1440) this happens: http://imgur.com/a/rcbJK.

用于处理文本的代码为: http://imgur.com/a/c316e .

The code for processing the text is: http://imgur.com/a/c316e.

我曾尝试扩展Label的范围,因为我认为这可能会限制文本的显示,但仍无法正确显示.

I've tried expanding the bounds of the Label because I thought that it might be constricting the text, but it still won't display properly.

这可能是什么原因造成的?

What could be causing this?

推荐答案

不同的手机的屏幕尺寸具有不同的宽高比.这就是它显示不同屏幕的原因.为避免此问题,您必须使用viewPort.因此,您将能够处理不同的屏幕尺寸.有关更多详细信息,您必须阅读l​​ibgdx文档.我在这里发布了示例代码,可以帮助您处理不同的屏幕尺寸.主要使用三种视口1)fillviewport2)fitviewPort3)stretchviewport这是详细的文档.

The different mobile phone has the different aspect ratio in their screen size . that is the reason it shows different different screen. to avoid this problem you must use the viewPort. So you will be able to handle the different screen size. for more details, you must read the libgdx documentation. here I'm posting a sample code which can help you to handle the different screen size. there are three kinds of viewports mainly using1) fillviewport2) fitviewPort3)stretchviewporthere is the documentation in detail.

https://libgdx. badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/viewport/FillViewport.html

public class myGame extends ApplicationAdapter {

public OrthographicCamera camera;
public Viewport viewPort;
private SpriteBatch batch;

public myGame() {

}

@Override
public void create() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();

    camera = new OrthographicCamera();
    camera.position.set(0, 0, 0);
    camera.update();
    camera.setToOrtho(false, 1280, 800);
    viewPort = new FillViewport(1280, 800, camera);


}

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





@Override
public void render() {
    Gdx.gl.glClearColor(1, 1, 1, 1);
    Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
    float deltaTime = Gdx.graphics.getDeltaTime();
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    batch.draw(sprie,0,0)
    batch.end();

}

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

@Override
public void pause() {
}

@Override
public void resume() {
}
}
// don't copy paste it . just try to understand and implement it.

这篇关于LibGDX文本无法在大屏幕上正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:21