<small id='xhpPH'></small><noframes id='xhpPH'>

    <legend id='xhpPH'><style id='xhpPH'><dir id='xhpPH'><q id='xhpPH'></q></dir></style></legend>
    • <bdo id='xhpPH'></bdo><ul id='xhpPH'></ul>
  1. <i id='xhpPH'><tr id='xhpPH'><dt id='xhpPH'><q id='xhpPH'><span id='xhpPH'><b id='xhpPH'><form id='xhpPH'><ins id='xhpPH'></ins><ul id='xhpPH'></ul><sub id='xhpPH'></sub></form><legend id='xhpPH'></legend><bdo id='xhpPH'><pre id='xhpPH'><center id='xhpPH'></center></pre></bdo></b><th id='xhpPH'></th></span></q></dt></tr></i><div id='xhpPH'><tfoot id='xhpPH'></tfoot><dl id='xhpPH'><fieldset id='xhpPH'></fieldset></dl></div>
    <tfoot id='xhpPH'></tfoot>

      某些设备的 LibGdx-ViewPort 宽度和高度不匹配

      时间:2023-05-19
        <tbody id='QNQrK'></tbody>

        <bdo id='QNQrK'></bdo><ul id='QNQrK'></ul>
      • <tfoot id='QNQrK'></tfoot>

              <small id='QNQrK'></small><noframes id='QNQrK'>

              <i id='QNQrK'><tr id='QNQrK'><dt id='QNQrK'><q id='QNQrK'><span id='QNQrK'><b id='QNQrK'><form id='QNQrK'><ins id='QNQrK'></ins><ul id='QNQrK'></ul><sub id='QNQrK'></sub></form><legend id='QNQrK'></legend><bdo id='QNQrK'><pre id='QNQrK'><center id='QNQrK'></center></pre></bdo></b><th id='QNQrK'></th></span></q></dt></tr></i><div id='QNQrK'><tfoot id='QNQrK'></tfoot><dl id='QNQrK'><fieldset id='QNQrK'></fieldset></dl></div>
              <legend id='QNQrK'><style id='QNQrK'><dir id='QNQrK'><q id='QNQrK'></q></dir></style></legend>

                本文介绍了某些设备的 LibGdx-ViewPort 宽度和高度不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我正在为我的 libGdx 风景游戏使用这样的视口.

                I am using a Viewport for my libGdx landscape game like this.

                public static final int WORLD_WIDTH = 1280;
                public static final int WORLD_HEIGHT = 800;
                
                camera = new OrthographicCamera();
                float aspectRatio = Constants.WORLD_WIDTH / Constants.WORLD_HEIGHT; 
                
                ViewPort viewPort = new FillViewport(WORLD_WIDTH * aspectRatio,WORLD_HEIGHT, camera);
                

                我正在使用这个宽度和高度方面的所有位置.

                I am using all positions in terms of this width and height.

                除了屏幕分辨率大于 1300 的设备外,它在所有设备上都可以正常工作.在分辨率大于 1300 的设备中,只能看到游戏的中间部分.我尝试在分辨率更高的设备上使用拉伸视口,但它会拉伸所有游戏元素.

                It is working fine in all devices except device that have screen resolution greater than 1300. In device that have greater resolution than 1300,only middle part of the game is visible.I tried using stretched viewport for the greater resolution device,but it is giving all game elements stretched.

                如何让我的游戏在所有设备上都能正常运行?是否需要更改视口?

                How can I make my game working in all devices fine?Do I need to change the viewport?

                推荐答案

                我终于成功了.我不确定这是否是解决此类问题的正确方法.我是这样做的;

                Finally I made it work. I am not sure whether this is the correct way to solve such problems. I did it like this;

                    camera = new OrthographicCamera();
                    if(screenHeight>1300)
                    {
                
                        Constants.WORLD_WIDTH=1280;
                        Constants.WORLD_HEIGHT=960;
                
                    }
                    else{
                        Constants.WORLD_WIDTH=1280;
                        Constants.WORLD_HEIGHT=800;
                
                    }
                     viewPort = new FillViewport(Constants.WORLD_WIDTH, Constants.WORLD_HEIGHT, camera);
                     viewPort.apply();
                

                我为所有分辨率更高的设备使用了 1280x960 的 viewPort 宽度,同时为所有其他屏幕宽度小于 1300 的设备保持 1280x800 分辨率.在绘制背景时,我使用视口宽度和高度来设置大小.

                I used a viewPort width of 1280x960 for all greater resolution devices while keeping 1280x800 resolution for all other devices that has screen width less than 1300. While drawing background I used viewport width and height to set the size like this.

                bgSprite=new Sprite(bgTexture);
                    bgSprite.setPosition(Constants.BG_X,Constants.BG_Y);
                bgSprite.setSize(game.viewPort.getWorldWidth(),game.viewPort.getWorldHeight());
                

                不确定这是正确的方法,但这样做解决了我的问题.

                Not sure this the right way,but doing this solved my problem.

                这篇关于某些设备的 LibGdx-ViewPort 宽度和高度不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Libgdx 的世界单位 下一篇:LibGDX 中的分屏

                相关文章

                最新文章

              1. <small id='hracV'></small><noframes id='hracV'>

                <legend id='hracV'><style id='hracV'><dir id='hracV'><q id='hracV'></q></dir></style></legend>
                  <i id='hracV'><tr id='hracV'><dt id='hracV'><q id='hracV'><span id='hracV'><b id='hracV'><form id='hracV'><ins id='hracV'></ins><ul id='hracV'></ul><sub id='hracV'></sub></form><legend id='hracV'></legend><bdo id='hracV'><pre id='hracV'><center id='hracV'></center></pre></bdo></b><th id='hracV'></th></span></q></dt></tr></i><div id='hracV'><tfoot id='hracV'></tfoot><dl id='hracV'><fieldset id='hracV'></fieldset></dl></div>

                    • <bdo id='hracV'></bdo><ul id='hracV'></ul>
                  1. <tfoot id='hracV'></tfoot>