我得到了 FitViewport具有虚拟宽度和虚拟高度。当屏幕的宽高比大于我的虚拟分辨率时,就会添加黑条。我想在这些信箱内画一些东西。
我尝试这样做,但只绘制虚拟分辨率“内部”的对象,“外部”的对象不可见:
viewport = new FitViewport(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, cam);
viewport.apply();
batch.setProjectionMatrix(cam.combined);
batch.begin();
batch.draw(texture, viewport.getRightGutterX(), 0);
batch.end();
如何在信箱内绘图?
最佳答案
您需要第二个视口(viewport),可能是与 FitViewport 具有相同虚拟尺寸的 ExtendViewport。
//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();
如果您想确保边框内容不会与您的游戏重叠,您可以交换上面的绘制顺序。
或者您可以只使用 ExtendViewport 来开始所有操作。
关于java - LibGDX:如何在FitViewport的黑条区域中绘制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34120303/