修改坐标系中LibGDX(JAVA) [英] Changing the Coordinate System in LibGDX (Java)

查看:264
本文介绍了修改坐标系中LibGDX(JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LibGDX具有坐标系统,其中(0,0)是在左下角。 (这样的形象: http://i.stack.imgur.com/jVrJ0.png

LibGDX has a coordinate system where (0,0) is at the bottom-left. (like this image: http://i.stack.imgur.com/jVrJ0.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.

这篇关于修改坐标系中LibGDX(JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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