使用camera.setToOrtho(假,GAME_WIDTH,GAME_HEIGHT)当libgdx扭曲质感;质感、setToOrtho、camera、GAME_WIDTH

2023-09-04 23:02:34 作者:天杀的可爱

我'试图让libgdx游戏,ADN我已经得到了2个问题,现在: 1.当使用camera.setToOrtho(假,GAME_WIDTH,GAME_HEIGHT)即时通讯;我的球员textrure是歪歪,一只眼睛大于另一个。 2.使用即时通讯这台相机和viweport:

I'am trying to make libgdx game, adn i've got 2 problems now: 1. When im using camera.setToOrtho(false, GAME_WIDTH, GAME_HEIGHT); my textrure of player is distored, one eye is bigger than another. 2. Im using this camera and viweport:

camera= new OrthographicCamera(GAME_WIDTH,GAME_HEIGHT);
camera.setToOrtho(false, GAME_WIDTH, GAME_HEIGHT);
viewport = new StretchViewport(GAME_WIDTH,GAME_HEIGHT,camera); 

和当我这样做:

touchPos.set(Gdx.input.getX(1),Gdx.input.getY(1),0);
 game.camera.unproject(touchPos);
System.out.println(touchPos.x+" "+ touchPos.y);

我得到0 0在右上角,但我的性格巫线0 0是图中左下角。

I get 0 0 in right top corner but my character witch cords 0 0 is drawing in left bottom corner.

当我使用:

 game.camera = new OrthographicCamera(820,480);
game.viewport = new FillViewport(820,480,game.camera);

我必须使用game.batch.setProjectionMatrix(game.camera.combined);

i must use game.batch.setProjectionMatrix(game.camera.combined);

当我使用code我有corectly工作unproject方法和坐标系统,但我已经得到了歪歪的质感。

when i use this code i've got corectly working unproject method and coordinate system but i've got distored texture.

当我使用:

camera = new PerspectiveCamera();
viewport = new StretchViewport(900, 470, camera);

我得歪歪的质感和不错的coords系统。我可以'T使用:game.batch.setProjectionMatrix(game.camera.combined);

i've got distored texture and bad coords system. and i can 't use :game.batch.setProjectionMatrix(game.camera.combined);

推荐答案

这是扭曲的,因为你使用的是固定宽度和高度的摄像头,所以它只是延伸你把它适合任何大小的窗口/屏幕

It is distorted because you are using a fixed width and height for the camera, so it simply stretches to fit whatever size window/screen you're putting it on.

顺便说一句,StretchViewport做同样的事情(扭曲现场适合你把它给了窗口的尺寸)。但是,你刚刚创建了一个视窗,而不实际调用更新()就可以了,所以它没有做任何事情。

Incidentally, StretchViewport does the same thing (distorts the scene to fit the dimensions you gave it to the window). But you just created a viewport without actually calling update() on it, so it's not doing anything.

您很可能希望使用ExtendViewport或FillViewport避免拉伸,但其他选项。阅读关于他们这里。

You most likely want to use ExtendViewport or FillViewport to avoid stretching, but other options are available. Read about them here.

您的视口将无法正确地响应屏幕旋转(或桌面窗口调整大小),除非你把 viewport.update(宽,高)进入调整大小的方法。而且你要叫更新上它至少一次不分,使用实际屏幕尺寸。这是最方便的,只需把 viewport.update(宽,高)进入调整大小的方法。

Your viewport won't properly respond to screen rotations (or desktop window resize) unless you put viewport.update(width,height) into the resize method. And you have to call update on it at least once regardless, using the actual screen dimensions. This is most convenient by simply putting viewport.update(width,height) into the resize method.