所以,我将LibGDX用于我即将推出的应用程序。
我使用FitViewport来确保16:9的宽高比。 因此,其他宽高比超过16:9的玩家将在网站上使用黑条。
绘制填充背景图像的屏幕的最佳方法是什么,该图像还覆盖了黑条所在的区域?
camera = new OrthographicCamera();
viewport = new FitViewport(WIDTH, HEIGHT, camera);
viewport.apply();
camera.position.set(WIDTH / 2, HEIGHT / 2, 0);
camera.update();
这就是我目前如何设置我的相机/视口。
然后我用SpriteBatch在其上绘制内容。
Gdx.gl.glClearColor(1, 1, 1, 1);
这就是我目前至少如何将黑条的颜色更改为任何RGB颜色。
答案 0 :(得分:3)
在我看来,最好的想法是创建第二个阶段,它只是出于背景目的而拥有Viewport
。第二个Viewport
不应该是 FillViewport - 它会根据我的经验展示你的图形。我认为 ExtendViewport 在这种情况下更好。
那应该怎么看:
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 );
现在只需处理渲染方法中的新阶段。
backStage.act();
stage.act();
backStage.draw(); //backStage first - we want it under stage
stage.draw();
在更新中更新新的Viewport
或像旧的更新。就是这样。
在此处详细了解Viewports
:https://github.com/libgdx/libgdx/wiki/Viewports