Libgdx camera/scaling issue(Libgdx 相机/缩放问题)
问题描述
这只是一个非常快速的帖子,想知道我做错了什么?
This is just a really quick post wondering what i have done wrong?
我希望使用我拥有的任何屏幕尺寸在整个屏幕上填充背景,但这并不能使它起作用.这里是所有代码:
I want the background to be filled on the whole screen with whatever screen sizes i have but this does not make it work. Here is all the code:
// Variables
Jump game;
OrthographicCamera cam;
SpriteBatch sb;
// Variables
public SplashScreen(Jump game)
{
this.game = game;
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.translate(cam.viewportWidth / 2, cam.viewportHeight / 2);
sb = new SpriteBatch();
}
public void show()
{
}
public void render(float delta)
{
Gdx.gl20.glClearColor(0.2F, 0.6F, 1F, 1F);
Gdx.gl20.glClear(GL20.GL_COLOR_BUFFER_BIT);
cam.update();
sb.begin();
sb.setProjectionMatrix(cam.combined);
sb.draw(Assets.splash_spr_background, 0, 0);
sb.end();
}
谢谢!:)
推荐答案
问题是您的资产与视口大小不同.请参阅下面的链接.Libgdx 使用 Viewport 类来处理这个问题.
The problem is your asset is not the same size as the viewport. See the links below. Libgdx uses the Viewport class to handle this.
如何处理libGDX中不同的纵横比?
如何根据不同缩放图片libgdx 中的屏幕分辨率
https://github.com/libgdx/libgdx/wiki/Viewports
这篇关于Libgdx 相机/缩放问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Libgdx 相机/缩放问题


- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 获取数字的最后一位 2022-01-01