在 Android 上创建与分辨率无关的游戏
我对 Android 游戏开发(以及一般的 Android 开发)还很陌生。
当我为我的第一款游戏创建背景时,我的第一个问题出现了:我应该选择哪种尺寸? 例如,如果我选择 800x480,它在其他分辨率下显示效果是否良好? 那我的主角呢?如果我让它每帧移动 5 像素(我已经知道如何使其与 fps 无关,这只是一个例子),那么在 320 像素宽度的屏幕上移动 5 像素与在 800 像素宽度的屏幕上移动 5 像素是不一样的。 对此有什么建议吗?
谢谢
I'm quite new to Android game development (and Android development in general).
My first question came when I was creating the background for my first game: which size should I choose?
If I choose 800x480 for example, will it show good on any other resolutions?
And what about my main character? If I make it move 5px/frame (I already know how to make it fps independent, it's just an example), it's not the same to move 5 pixels on a 320px-width screen than on a 800px-width one.
Any advices on this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该为您希望支持的每种屏幕密度拥有单独的资源文件。
You should have separate resource files for each of the screen densities you wish to support.
选择您计划进行开发的设备本机支持的背景大小,并在项目接近尾声时担心支持非本机分辨率或添加其他分辨率的资源。不要陷入杂草之中。
Pick the background size that's supported natively on the device you plan on developing on, and worry about supporting non-native resolutions or adding resources for other resolutions when you're near the end of the project. Don't get bogged down in the weeds.
正如 @PaulSonier 所说,直到最后都不要担心支持多个分辨率。
目前仅在一台设备上进行开发,并尽可能使用“dp”或“dip”单位。这将使最终更容易支持多种屏幕尺寸和密度。
至于背景,请考虑使用9-patches。
As @PaulSonier said, don't worry about supporting multiple resolutions until the end.
For now just develop on one device and use 'dp' or 'dip' units whenever possible. This will make it easier at the end to support multiple screen sizes and densities.
As for the background, consider using 9-patches.
对于您想要支持的每种分辨率,您都应该有一组单独的图形。如果您确实想覆盖所有当前设备并在每台设备上都拥有清晰锐利的图形,并且希望确保宽高比不会使您的游戏在某些设备上看起来很奇怪,那么您需要准备您的资源采用以下分辨率和比例:
来源:http://bigosaur.com /blog/31-android-resolutions-definite-answer
最好的解决方案是至少绘制所有全屏图像2733x2134 像素,然后按比例缩小。好吧,您可以缩小图像,如果您有文本,最好使用较小的字体大小并将其放在图像上。您可以在运行时执行此操作或提前预渲染文本。您可以使用 ImageMagick 自动执行 6 种不同尺寸的所有操作,这样您就不必手动执行此操作。
You should have a separate set of graphics for each of the resolutions you want to support. If you really want to cover all the current devices and have the crisp and sharp graphics on every one of those and you want to make sure that the aspect ratio doesn't make your game look weird on some devices, you need to prepare your assets in the following resolutions and scales:
Source: http://bigosaur.com/blog/31-android-resolutions-definite-answer
The best solution is to draw all full-screen images at least 2733x2134 pixels and then scale it down. Well, you can scale down images, if you have text, better to use smaller font size and put it over the image. You can do this at run-time or pre-render the text in advance. You can use ImageMagick to automate all that for 6 different sizes so you don't do it manually.