简体   繁体   English

调整舞台和摄像机的大小

[英]Resizing the stage and camera

I have a problem with my resizing method in libgdx, when I ran my game on my phone all works fine, but when I ran the game in another phone which is more bigger all is getting smaller and it just look bad. 我在libgdx中调整大小的方法存在问题,当我在手机上运行游戏时一切正常,但是当我在更大的另一部手机上运行游戏时,一切都变小了,看起来好像很糟糕。

Here is my resizing method: 这是我的调整大小方法:

@Override
public void resize(int width, int height) {

    ...

    camera.viewportHeight = height /  1.1f;
    camera.viewportWidth = width / 1.1f;



    stage.setViewport(width, height, true);

        table.invalidateHierarchy();
        table.setSize(width, height);
        table2.invalidateHierarchy();
        table2.setSize(width, height);
        table3.invalidateHierarchy(); 
        table3.setSize(width, height);
        table4.invalidateHierarchy();
        table4.setSize(width, height);

}

And this method just give a bad effect. 而且这种方法效果不好。 How can I fix this? 我怎样才能解决这个问题?

The perfect question to introduce Viewport , which has been added today . 引入Viewport的完美问题已在今天添加。

Viewports are made especially to deal with this very problem. 视口是专门为处理此问题而设计的。 Have a look at this news and the wiki page to see how those work. 查看此新闻Wiki页面以了解其工作原理。

However, those are only available in the nightly build. 但是,这些仅在每晚版本中可用。

What you are actually doing at the moment, is implementing the " ScreenViewport " yourself, which always keeps the size of the screen, which leads to no stretching, but it will show more or less of your world. 您目前实际在做什么,就是自己实现“ ScreenViewport ”,它始终保持屏幕的大小,这不会导致拉伸,但是会或多或少显示您的世界。

What you are probably looking for, is FitViewport or maybe StretchViewport . 您可能正在寻找的是FitViewportStretchViewport Those offer you a virtual screen size and will scale this to fit your screen. 这些为您提供虚拟屏幕尺寸,并将其缩放以适合您的屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM