简体   繁体   English

libgdx最佳高度和宽度

[英]libgdx optimal Height and Width

Does it matter what height and width I use for my game? 我在游戏中使用什么高度和宽度是否重要? In my game I have a few polygons, they all are connected to images that I have painted, but when I have width and height as 800x480 I have to paint the images very small, this causes them to get blurry. 在我的游戏中,我有一些多边形,它们都与我绘制的图像相连,但是当我的宽度和高度为800x480时,我必须将图像绘制得非常小,这会使它们变得模糊。 Also, I don't really understand how this behaves on different sized phone screens.., does the images I have painted get streched, or do they stay small, even on big tablets? 另外,我不太了解在不同尺寸的手机屏幕上的行为。.我绘制的图像会被拉长吗,还是即使在大平板电脑上也不会变小? So my question is basically what is the optimal width and height to have on a libgdx game? 所以我的问题基本上是libgdx游戏的最佳宽度和高度是多少?

This is a part of my code, to maybe help you understand what I mean 这是我的代码的一部分,也许可以帮助您了解我的意思

    WIDTH = Gdx.graphics.getWidth();
    HEIGHT = Gdx.graphics.getHeight();

    camera = new OrthographicCamera();
    camera.setToOrtho(false, 800, 480 );

What will happen if I change these values? 如果更改这些值会怎样? What would it be best to change them to? 最好将它们更改为什么?

I was reading on a tutorial of sorts, but they didn't really talk about this part. 我正在阅读各种教程,但他们并没有真正谈论这部分。

Do I have to do something complicated to get my painted images to look decent on all devices? 我是否需要做一些复杂的事情才能使我绘制的图像在所有设备上看起来都不错?

EDIT: 编辑:

This is how I currently implement a cloud into my game: 这是我目前在游戏中实现云计算的方式:

public class AnotherScreen implements Screen{

Polygon cloudPoly;
Texture cloud;

    @Override
public void render(float delta) {

    batch.setProjectionMatrix(camera.combined);

    batch.begin();
    renderBackground();
    batch.draw(cloud,cloudPoly.getX(),cloudPoly.getY());
    batch.end();

    }

    @Override
public void show() {
    cloud = new Texture(Gdx.files.internal("assets/textures/cloud.png"));
            cloudPoly = new Polygon();
    cloudPoly.setPosition(MathUtils.random(350,600),MathUtils.random(380,440));

    // theses vertices are just a little square atm
    float[] cloudVertices = new float[] {
            0,0,
            0,20,
            20,20,
            20,0
    };
    cloudPoly.setVertices(cloudVertices);
    }

} }

The cloud image has width 256p and height 128p, when I set 'camera.setToOrtho(false, 800, 480 );' 当我设置'camera.setToOrtho(false,800,480);'时,云图像的宽度为256p,高度为128p。 won't this cloud always stay in proportion? 难道这朵云不会一直保持比例吗?

I am sorry if I am unclear, I am a new programmer and my english could be better, love you doh for staying with me! 如果我不清楚,我很抱歉,我是一名新程序员,我的英语水平会更好,爱你,待在我身边!

does the images I have painted get streched, or do they stay small, even on big tablets? 我所绘制的图像会变得拉长,还是即使在大平板电脑上也不会变小?

One of the greatest features of libgdx is that it lets you do things exactly as you want them. libgdx的最大功能之一就是可以让您完全按照自己的意愿去做。 So, it is really your choice. 因此,这确实是您的选择。 With this snippet 有了这个片段

WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();

camera = new OrthographicCamera();
camera.setToOrtho(false, WIDTH, HEIGHT);

You would have a different viewport size in every different screen size. 在每个不同的屏幕尺寸中,您将拥有不同的视口尺寸。 So your images would stay small. 因此,您的图像会很小。

In the other hand, if you use predefined values for the viewport like: 另一方面,如果您为视口使用预定义的值,例如:

WIDTH = 800;
HEIGHT = 480;

camera = new OrthographicCamera();
camera.setToOrtho(false, WIDTH, HEIGHT);

You would get the same viewport for every screen and the images would stretch to occupy the same space in each axis. 您将为每个屏幕获得相同的视口,并且图像将拉伸以占据每个轴上的相同空间。 This won't necessarily be the same for each axis. 每个轴不一定相同。 So a perfect square image in one screen may look like a rectangle in another screen with a different xy ratio. 因此,一个屏幕上的理想正方形图像可能看起来像另一屏幕上的矩形,但xy比率不同。

There is a third option, you can fix one side and let the other be calculated, so you keep the ratio of your images (a square stays as square). 第三种选择是,您可以固定一侧,然后计算另一侧,因此可以保持图像的比例(正方形保持正方形)。 You must decide what will be the fixed side. 您必须决定什么是固定面。 For a game like Super Mario Bros I would recommend you to fix the height and calculate the width: 对于像《 超级马里奥兄弟》这样的游戏,我建议您固定高度并计算宽度:

HEIGHT = 480;
WIDTH = (Gdx.graphics.getWidth()/Gdx.graphics.getHeight())*HEIGHT;

camera = new OrthographicCamera();
camera.setToOrtho(false, WIDTH, HEIGHT);

Every screen would see the same height in the game world. 在游戏世界中,每个屏幕都会看到相同的高度。 But some screens would see more in the width than others. 但是某些屏幕在宽度上会比其他屏幕更大。 If thats a problem for you (you want them to see the same ammount of the world but keep the ratio too), than adding black bars to each side is an option. 如果那对您来说是个问题(您希望他们看到相同的世界数量,但也要保持比例),那么可以选择在每一侧添加黑条。

So my question is basically what is the optimal width and height to have on a libgdx game? 所以我的问题基本上是libgdx游戏的最佳宽度和高度是多少?

The optimal solution is having a different set of images for several resolutions. 最佳解决方案是针对几种分辨率使用一组不同的图像。 And choosing whats the most appropiate at runtime. 并在运行时选择最合适的功能。 But that increases the game size a lot. 但这极大地增加了游戏的大小。

Another dirty way is having only one big set and let the images shrink in lower resolutions. 另一种肮脏的方法是仅设置一个较大的集,然后以较低的分辨率缩小图像。 It looks better than the inverse. 它看起来比逆向更好。 But some people think this is just too dirty :p (not me, so I recommend it). 但是有些人认为这太脏了:p(不是我,所以我推荐它)。

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

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