如何让舞台在libgdx的中心? [英] how to get stage in the center in libgdx?

查看:170
本文介绍了如何让舞台在libgdx的中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的形象是大小720×480的和舞台一样大小的。布尔参数,无论是伸展台上还是不保持虚假的,因此宽高比保持不变,现在的问题我得到一个黑色区域是在我想要被我中心现场屏幕两侧显示。下面的链接指向一个文件,其中更清楚地看到问题,即对齐图像左下方我希望它为中心,使黑色区域的顶部和底部平分。

My image is of size 720x480 and stage is of same size. 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

推荐答案

您必须指定X和Y坐标如下方式

You have to specify X and Y coordinate as the following way

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

您必须calaculate图像的中心。使用这种方式,你可以把你的形象在屏幕的中央。另外这里我雪碧用户显示图像。

You have to calaculate center of the image. Using this way you can put your image in center of the screen. Also here I user Sprite to display image.

这篇关于如何让舞台在libgdx的中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆