修改坐标系中LibGDX(JAVA)坐标系、LibGDX、JAVA

2023-09-07 12:10:22 作者:爱情,我戒了

LibGDX具有坐标系统,其中(0,0)是在左下角。 (这样的形象: https://m.xsw88.com/allimgs/daicuo/20230907/5439.png )

LibGDX has a coordinate system where (0,0) is at the bottom-left. (like this image: https://m.xsw88.com/allimgs/daicuo/20230907/5439.png)

这有我打我的头撞墙,这主要是因为我移植一个游戏我已经与通常的坐标系(其中,0,0是左上角)进行。

This has me beating my head against a wall, mainly because I'm porting a game I had already made with the usual coordinate system (where 0,0 is in the Top Left Corner).

我的问题:有没有改变这个坐标系中的任何简单的方法

推荐答案

如果您使用相机(你应该)修改坐标系是pretty的简单:

If you use a Camera (which you should) changing the coordinate system is pretty simple:

camera= new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

如果您使用TextureRegions和/或TextureAtlas,所有你需要做的,除了是调用region.flip(假,真)。

If you use TextureRegions and/or a TextureAtlas, all you need to do in addition to that is call region.flip(false, true).

是我们采用Y-由默认值(你可以很容易地改变,因为如上图所示),原因如下:

The reasons we use y-up by default (which you can easily change as illustrated above) are as follows:

您的模拟code将最有可能使用一个标准的欧几里得坐标系的y了 如果你去3D你有Y型可达 在默认坐标系递给在OpenGL的权利,为Y-起来。你当然可以很容易地改变某些矩阵的魔力。

在libgdx只有两个地方,我们采用Y-下来是:

The only two places in libgdx where we use y-down are:

在像素图的坐标(顶部左上角的起源,Y-下) 触摸事件的坐标它在窗口坐标给出(顶部左上角的起源,Y-下)

同样,你可以很容易地改变所使用的坐标系,以任何你想要使用任何相机或矩阵数学的一点点。

Again, you can easily change the used coordinate system to whatever you want using either Camera or a tiny bit of matrix math.

 
精彩推荐
图片推荐