借助Viewports 和Scene2d Stages,您不必创建自己的机制,老实说根本不必关心分辨率。
视口定义了由于分辨率变化而调整大小时如何处理屏幕 - 如果它应该拉伸?或者也许保持不变?有很多种视口(每种视口都只是另一个类,因此您要选择视口来创建所选类的对象),每种视口都有自己的行为。
您可以在此处阅读有关 Viewport 的更多信息:
https://github.com/libgdx/libgdx/wiki/Viewports
舞台是一种抽象的表现形式——让我们想想剧院中的舞台和舞台上的演员。舞台只是您在渲染部分中绘制的一种对象处理程序。演员是图像、标签、按钮等。
您可以在此处阅读有关 Stage 的更多信息:
您所要做的就是创建一个舞台,将您的演员(按钮、图像、标签...)添加到其中并将其设置为您的自定义视口。
public GameScreen(Main game)
{
super(game);
viewport = new ExtendViewport(this.screenWidth, this.screenHeight); // viewport definition is ExtendViewport viewport; screenWidth and Height are defined width and height of your screen
stage = new MyStage(); //stage definition is Stage stage;
stage.setViewport(this.viewport);
}
@Override
protected void show()
{
...
stage.addActor( someLabel ); //someLabel definition is Label someLabel; and it is created somewhere before
...
}
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
this.viewport.update(this.screenWidth, this.screenHeight);
this.stage.act();
this.stage.draw();
}
@Override
public void resize(int width, int height)
{
//you need this function to keep screen size updated
this.screenWidth = width;
this.screenHeight = height;
}
现在关于您的精灵大小 - 如果它是移动应用程序,那么拥有非常非常大的资源并不是很好 - 大多数移动设备的分辨率都很小,因此在您的应用程序中保留大文件并不好 - 记住这一点占用磁盘空间。