简体   繁体   English

如何在libgdx中心获得舞台?

[英]how to get stage in the center in libgdx?

My image is of size 720x480 and stage is of same size. 我的图片大小为720x480,舞台大小相同。 The boolean parameter, whether to stretch the stage or not is kept false, so that aspect ratio is maintained, now the problem i am getting that a black area is shown on either side of the screen I want my scene to be centered. 布尔参数,无论是否拉伸舞台都保持为假,因此保持纵横比,现在我得到的问题是在屏幕的任一侧显示黑色区域我希望我的场景居中。 The link below refers a file, which shows the problem more clearly, that image is aligned to the bottom left i want it to be centered so that the black area is divided equally on top and the bottom. 下面的链接指的是一个文件,它更清楚地显示问题,图像对齐到左下方我希望它居中,以便黑色区域在顶部和底部平均分配。

what is the approach to solve this? 解决这个问题的方法是什么?

http://badlogicgames.com/forum/viewtopic.php?f=11&t=3398 http://badlogicgames.com/forum/viewtopic.php?f=11&t=3398

You have to specify X and Y coordinate as the following way 您必须按以下方式指定X和Y坐标

X = (Gdx.graphics.getWidth() - sprite.getRegionWidth()) / 2.0f;
Y = (Gdx.graphics.getHeight() - sprite.getRegionHeight()) / 2.0f, sprite.getRegionWidth()/2.0f;

You have to calaculate center of the image. 你必须calaculate图像的中心。 Using this way you can put your image in center of the screen. 使用这种方式,您可以将图像放在屏幕的中央。 Also here I user Sprite to display image. 在这里我用户Sprite来显示图像。

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

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