LibGDX:如何在FitViewport的黑色条区域中绘制? [英] LibGDX: How to draw in the area of the black bars of a FitViewport?

查看:103
本文介绍了LibGDX:如何在FitViewport的黑色条区域中绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 FitViewport 具有虚拟宽度和虚拟高度.当屏幕获得比我的虚拟分辨率更高的长宽比时,会添加黑条.我想在这些信箱中画些东西.

I got a FitViewport with a virtual width and virtual height. When the screen got another aspect ratio than my virtual resolution black bars are added. I want to draw something inside these letterboxes.

我试图这样做,但是只绘制了我的虚拟分辨率内部"的对象,外部"的对象不可见:

I tried to do it that way, but only objects "inside" my virtual resolution are drawn, objects "outside" are just not visible:

viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, cam);
viewport.apply();

batch.setProjectionMatrix(cam.combined);

batch.begin();
batch.draw(texture, viewport.getRightGutterX(), 0);
batch.end();

如何在信箱中画图?

推荐答案

您将需要第二个视口,可能是ExtendViewport,其虚拟尺寸与FitViewport相同.

You would need a second viewport, probably ExtendViewport with the same virtual dimensions as your FitViewport.

//create:
fitViewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
extendViewport = new ExtendViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);

//resize:
fitViewport.update(width, height);
extendViewport.update(width, height);

//render:

fitViewport.apply();
batch.setProjectionMatrix(fitViewport.getCamera().combined);
batch.begin();
//draw game
batch.end();

extendViewport.apply();
batch.setProjectionMatrix(extendViewport.getCamera().combined);
batch.begin();
//draw stuff in border
batch.end();

如果要确保边框不会与游戏重叠,则可以交换上面的绘制顺序.

If you want to be sure the border stuff doesn't overlap your game, you could swap the draw order above.

或者您可以仅使用ExtendViewport来完成所有工作.

Or you could just use ExtendViewport to begin with for everything.

这篇关于LibGDX:如何在FitViewport的黑色条区域中绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆