LibGDX文本无法在大屏幕上正确显示

编程入门 行业动态 更新时间:2024-10-28 10:24:09
本文介绍了LibGDX文本无法在大屏幕上正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

The code for processing the text is: imgur/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)fillviewport 2)fitviewPort 3)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 using 1) fillviewport 2) fitviewPort 3)stretchviewport here is the documentation in detail.

libgdx. badlogicgames/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(camerabined); 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文本无法在大屏幕上正确显示

本文发布于:2023-07-26 18:18:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   正确   屏幕上   LibGDX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!