简体   繁体   English

适用于Android游戏的分辨率独立的图形

[英]resolution independent graphics for Android games

I'm developing an Android game using libgdx and define the virtual camera width/height to be: 800x1280. 我正在使用libgdx开发Android游戏,并将虚拟摄像头的宽度/高度定义为:800x1280。

I have 3 test devices: 我有3个测试设备:

  1. Nexus 5 1920 x 1080 display (445 ppi) Nexus 5 1920 x 1080显示屏(445 ppi)
  2. Nexus S 480 x 800 pixels (233 ppi) Nexus S 480 x 800像素(233 ppi)
  3. Nexus 10 2560 x 1600 (300 ppi) Nexus 10 2560 x 1600(300 ppi)

I'm using GIMP to develop the graphics. 我正在使用GIMP开发图形。 How do I pick a appropriate size in GIMP for sprites, coins and background picture so it won't be displayed pixelated? 如何在GIMP中为精灵,硬币和背景图片选择合适的尺寸,以免像素化显示? I don't just want to pick a extremely high resolution and increase the app size unnecessary. 我不只是想选择一个极高的分辨率并增加不必要的应用程序大小。 Would all graphics have to be a power of 2? 所有图形都必须是2的幂吗?

For OpenGL on phones it is kind of mandatory to have power of 2 textures but some devices may support non-power of 2 textures ( with some limitations ). 对于手机上的OpenGL,强制具有2纹理的能力是一种强制性要求,但是某些设备可能不支持2纹理的功率(有一些限制)。 So if you want to make sure it will work stick with power of 2 textures. 因此,如果您要确保它可以正常使用2种纹理的力量。

For generic drawing I think anything can go there is no limit, generic drawing I mean, bitmaps in the layout. 对于通用图纸,我认为任何事情都可以解决,而通用图纸是布局中的位图。

It is usually up to you how you solve the independence issue, since first of all you may suffer from aspect ratio problems which will cause distortion like 4:3 in 16:9 will be stretched so you have to do something about that, the usual way in 3D games is to let the camera "see" more in 16:9. 通常,由您来决定如何解决独立性问题,因为首先您可能会遇到宽高比问题,这会导致失真,例如16:9中的4:3会被拉伸,因此您必须对此做一些事情,通常3D游戏中的一种方式是让摄像机在16:9中“看到”更多。

Anyway generally you should use android's built-in method of selecting the best image set for the current display, as far as I know its not just about choosing a pixel size that is closest to what resolution you have since the actual pixels you will see may vary depending on the device ( ppi ). 无论如何,一般而言,您应该使用android的内置方法为当前显示器选择最佳图像集,据我所知,这不仅仅是选择与您所用分辨率最接近的像素大小,因为您将看到的实际像素可能取决于设备(ppi)。

The other way around this problem is that you may generate the images every time you run making it the most suitable every time, I'm saying that you store the source and pre-render the images on startup to make them the most appropriate. 解决此问题的另一种方法是,您可能会在每次运行时生成图像,从而使其每次都最合适。我的意思是,您存储源并在启动时预渲染图像以使其最合适。

So the best which gives a tradeoff between quality and speed is to have different sets for different screens and pick to best upon startup ( or let android do that for you ) and render with those images. 因此,要在质量和速度之间进行权衡的最佳方法是为不同的屏幕设置不同的设置,并在启动时选择最佳设置(或让android为您完成此操作)并使用这些图像进行渲染。 If you just want to use 1 set of images, try to tune it so it looks okay on the bigger screens since down scaling tends to look better than up scaling. 如果您只想使用一组图像,请尝试对其进行调整,以使其在较大的屏幕上看起来还可以,因为向下缩放往往比向上缩放更好。

If you use OpenGLES1.x, yes the textures must be power of 2. If you use OpenGLES2.0, then they aren't forced to, but some devices do not support them anyways. 如果使用OpenGLES1.x,是的,纹理必须是2的幂。如果使用OpenGLES2.0,则不会强制使用纹理,但是某些设备仍然不支持它们。

It is recommended you always use power of 2 textures. 建议您始终使用2种纹理的幂。 Try to get all the images in big atlases (1024x1024 for example). 尝试以大地图集(例如1024x1024)获取所有图像。 That will give you very big performance increase. 这将为您带来很大的性能提升。

Also I would recommend you to make the graphics for the camera viewport that you are already using (800x1280). 另外,我建议您为已经在使用的摄影机视口制作图形(800x1280)。
And decide if you want the graphics to be stretched in different screen ratios or having the sprites look the same but change how much of your world every user can see. 并确定是要以不同的屏幕比例拉伸图形还是让精灵看起来相同,但要更改每个用户可以看到的世界范围。

For the first, leave your viewport like that (800x1280) It will stretch automatically. 首先,将视口保持为这样(800x1280),它将自动拉伸。
For the second, make your longer side fixed and calculate the other side. 对于第二个,将您的较长边固定,然后计算另一边。 (or the other way around, it depends on if you want the user to see more or less in horizontal or vertical). (或者反过来,这取决于您是否希望用户在水平或垂直方向上看到更多或更少的内容)。 Something like this: 像这样:

cam = new OrthographicCamera(((float)Gdx.graphics.getWidth()/Gdx.graphics.getHeight())*800, 1280);

I suggest you to make them for 800x1280, and use the Linear filter for the images so they dont look pixelated when stretched/shrinked. 我建议您将它们的尺寸设置为800x1280,并对图像使用线性滤镜,这样它们在拉伸/收缩时就不会显得像素化。

texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

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

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