1. <legend id='x3xZX'><style id='x3xZX'><dir id='x3xZX'><q id='x3xZX'></q></dir></style></legend>
      2. <small id='x3xZX'></small><noframes id='x3xZX'>

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

        FitViewport 中的 LibGDX 背景图像

        时间:2023-05-19

        <legend id='9BVh4'><style id='9BVh4'><dir id='9BVh4'><q id='9BVh4'></q></dir></style></legend>

            <bdo id='9BVh4'></bdo><ul id='9BVh4'></ul>

            <small id='9BVh4'></small><noframes id='9BVh4'>

                <tbody id='9BVh4'></tbody>
                <i id='9BVh4'><tr id='9BVh4'><dt id='9BVh4'><q id='9BVh4'><span id='9BVh4'><b id='9BVh4'><form id='9BVh4'><ins id='9BVh4'></ins><ul id='9BVh4'></ul><sub id='9BVh4'></sub></form><legend id='9BVh4'></legend><bdo id='9BVh4'><pre id='9BVh4'><center id='9BVh4'></center></pre></bdo></b><th id='9BVh4'></th></span></q></dt></tr></i><div id='9BVh4'><tfoot id='9BVh4'></tfoot><dl id='9BVh4'><fieldset id='9BVh4'></fieldset></dl></div>
                  <tfoot id='9BVh4'></tfoot>
                • 本文介绍了FitViewport 中的 LibGDX 背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  所以,我正在为即将推出的应用程序使用 LibGDX.

                  So, I'm using LibGDX for my upcoming App.

                  我使用 FitViewport 来确保 16:9 的纵横比.因此,除 16:9 以外的其他宽高比的播放器将在站点出现黑条.

                  I use a FitViewport to ensure the 16:9 aspect ratio. So players with other aspect ratios than 16:9 will have black bars at sites.

                  最好的方法是绘制一个屏幕填充背景图像,它也覆盖了黑条所在的区域?

                      camera = new OrthographicCamera();
                      viewport = new FitViewport(WIDTH, HEIGHT, camera);
                      viewport.apply();
                      camera.position.set(WIDTH / 2, HEIGHT / 2, 0);
                      camera.update();
                  

                  这就是我目前设置相机/视口的方式.

                  Thats how I set up my camera/viewport currently.

                  然后我用 SpriteBatch 在上面画东西.

                  I then draw stuff on it with a SpriteBatch.

                  Gdx.gl.glClearColor(1, 1, 1, 1);
                  

                  这就是我目前至少将黑条的颜色更改为任何 RGB 颜色的方式.

                  That's how I currently at least change the color of the black bars, to any RGB color.

                  推荐答案

                  在我看来,最好的办法是创建第二个阶段,它自己的 Viewport 仅用于后台用途.第二个 Viewport 不应该是 FillViewport - 它会根据我的经验拉伸您的图形.我认为 ExtendViewport 在这种情况下会更好.

                  In my opinion, the best idea is to create a second stage and it's own Viewport only for background purposes. This second Viewport should not be FillViewport - it will strech your graphics from my experience. I think ExtendViewport is better in this case.

                  那么它应该是什么样子:

                  So how should it look:

                      Stage stage, backStage;
                      FitViewport viewport;
                      ExtendViewport backViewport;
                  
                      ...
                  
                      stage = new Stage(); //this is your normal stage you have now
                      stage.setViewport( yourFitViewport ); //here you are assingning fit viewport
                  
                      backViewport = new ExtendViewport( screenWidth, screenHeight );
                  
                      backStage = new Stage();
                      backStage.setViewport( backViewport ); 
                  
                      ...
                      //now add to backStage your background Image
                  
                      backStage.addActor( yourBackground );
                  

                  现在只需在渲染方法中处理新阶段.

                  Now just handle new stage in the render method.

                      backStage.act();
                      stage.act();
                  
                      backStage.draw(); //backStage first - we want it under stage
                      stage.draw();
                  

                  并在更新中更新新的 Viewport 或像旧的一样渲染.就是这样.

                  And update new Viewport in update or render like your old one. That's all.

                  在此处阅读有关 Viewports 的更多信息:https://github.com/libgdx/libgdx/wiki/Viewports

                  Read more about Viewports here: https://github.com/libgdx/libgdx/wiki/Viewports

                  这篇关于FitViewport 中的 LibGDX 背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何通过代理设置 libGDX 项目 下一篇:使用 libgdx 在运行时生成带有文本的纹理

                  相关文章

                  最新文章

                  • <bdo id='8fLCh'></bdo><ul id='8fLCh'></ul>

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

                • <tfoot id='8fLCh'></tfoot>
                  1. <small id='8fLCh'></small><noframes id='8fLCh'>

                    <legend id='8fLCh'><style id='8fLCh'><dir id='8fLCh'><q id='8fLCh'></q></dir></style></legend>