安卓游戏所有的屏幕尺寸工作 [英] Android game working on all screen sizes

查看:341
本文介绍了安卓游戏所有的屏幕尺寸工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对于〜10的屏幕的Andr​​oid游戏中指定的艺术大小。我希望游戏的API 8+运行,并且除在所有尺寸屏幕的小。

I'm trying to specify the art sizes for an Android game with ~10 screens. I want the game to run on API 8+, and on all size screens except "small".

由于我们使用API​​ 8,我用的是旧的屏幕的4类的功能 - 我打算支持

Since we're using API 8, I use the old "4 categories of screen" feature - I plan to support


  • 正常(480×320,和多达640×480)

  • 大(640×480和960×720)

  • XLARGE(960×720,以及高达1920 x 1200)

一个1920x1200的PNG文件是4.1MB〜。因此,其中10是41MB,我们已经差不多吹我们的50 MB应用程序大小限制(Play商店)。

A 1920x1200 png file is ~4.1MB. So 10 of them is 41MB, and we've almost blown our 50 MB app size limit (Play Store).

于是三个问题:
1.如何人民支持的详细艺术品的游戏画面?我一定要使用温和的有色9修补的PNG文件的背景?抑或是可行的所有艺术品商店在960x720大小,并允许它由Android大型和标准屏幕大小?这种规模共10档背景下约15 MB,这让35 MB的一切。

So three questions: 1. how do people support detailed artwork for game screens? Do I have to use bland colored 9 patch pngs files for the backgrounds? Or is it feasible to store all art at the 960x720 size, and allow it to be resized by Android for large and normal screens? 10 background files of this size total to about 15 MB, which leaves 35 MB for everything else.

如果我使用的JPG文件,而不是PNG图片?我会多少失去的质量?因为我会永远只能裁员,这应该是正常的吧?的960x720 JPG格式10只有4.3MB。

What if I used jpgs instead of pngs? How much quality would I lose? Since I would only ever be downsizing, this should be OK, right? 10 jpgs of 960x720 is only 4.3MB.


  1. 如果我允许的Andr​​oid来调整它,我怎么支持具有不同的纵横比大于4的屏幕:3的960x720?有没有在布局XML来指定的方式使用来自大文件夹中可绘制,但信箱,它搬上银幕,使最长尺寸正好能? (以及XLARGE屏幕比960x720大,只是把绘在屏幕的中间 - 不要伸展它的话)?

  1. If I allow Android to resize it, how do I support screens that have a different aspect ratio than the 4:3 of 960x720? Is there a way to specify in the layout XML "use the drawables from the large folder, but "letter box" it onto the screen, so that the longest dimension just fits" ? (And for xlarge screens bigger than 960x720, just put the drawable in the middle of the screen - don't stretch it at all)?

DPI分辨率不会纳入本呢? DPI只需要考虑当你想要的东西大致在不同解析度萤幕的大小相同,像一个图标或按钮。是否正确?

DPI resolution of the screen doesn't factor in this at all? DPI only needs to be taken into account when you want something to be roughly the same size on different res screens, like an icon or button. Correct?

好像这样的有一个众所周知的图案或模板解决的问题可循。怎么会有其他人来完成呢?每个人都请使用下载庞大的安装后(要避免)或9补丁背景?

Seems like this should be a solved problem with a well known pattern or template to follow. How have other people done it? Does everyone use either huge downloads post install (want to avoid) or 9 patch backgrounds?

先谢谢您的任何意见。我搜索在这里的几个方面,又看了看25过去答案,没有找到我所期待的。

Thanks in advance for any advice. I searched here on several terms, and looked at about 25 past answers, without finding what I am looking for.

彼得

推荐答案

复活死(线程):做事情的一种方法可能是只提供一组位图,做缩放自己。你可以提供一个大的位图和规模下来,或者提供的位图路中间和规模起来(对大屏幕),下(较小的大小)。

Resurrecting the dead (thread): one way of doing things could be to provide just one set of bitmaps and do the scaling yourself. You can either provide large bitmaps and scale them down, or provide middle of the road bitmaps and scale them up (for large screens) and down (for smaller sizes).

前者的好处是,你的图片在大屏幕大,你多一点面向未来的(如果你在code提供了这一点)。缺点是,你可以(实际上很可能会)遇到内存不足/解码时/在低端设备加载这些位图,即使仔细做,当它超过VM错误。所以我通常去的第二种方法。

The benefits of the former are that your art looks great on large screens and you are a bit more future proof (if you provide for this in your code). The downside is that you could (and actually likely will) run into Out Of Memory/Exceeding VM errors when decoding/loading these bitmaps on lower-end devices, even when doing it carefully. So I usually go for the second approach.

向上扩展可以做许多方式,但一个是刚刚在BMP装载在它的默认大小(使用getResources()。openRawResource(ID)或BitmapFactory.de codeResource(等),甚至更好使用inputstreams或[根据一些最好的方法]加载/创建使用的FileDescriptor方法),然后通过创建使用createScaledBitmap()另一BMP或绘图画布​​它画到目标Rectangle(更好的内存明智),它的规模。
对于缩减你可以再次使用BitmapOptions像.inScaled或者,使用一个较小的目标矩形在画布drawcall。

Scaling up can be done a number of ways, but one is to just load in the bmp at it's default size (use getResources().openRawResource(id) or BitmapFactory.decodeResource(etc) or even better use inputstreams or [according to some the best method] load/create using the FileDescriptor methods) and then scale it either by creating another bmp using createScaledBitmap() or if drawing to a canvas draw it to a destination Rectangle (better memory wise). For scaling down you can either use BitmapOptions like .inScaled or, again, use a smaller destination Rect in your canvas drawcall.

这样做,这样是更好的方式(对于游戏)不是让Android的规模,你使用这些桶进行(华电国际等),速度更快,占用内存更少,如果做得正确。

Doing it this way is way better and (for a game) faster than letting Android scale for you using those buckets (hdpi etc) and uses less memory if done right.

但要注意一些位图加载方法是有点马车和打造BMP太大的VM的错误。也学会处理您的最佳管理措施适当的;很多人都和谷歌/ Google员工说Android的做到这一点,你没有设置你的骨形成蛋白为null和回收()他们,但到目前为止,我发现,你怎么做。另一个需要注意的是设置正确的选项(过滤/反锯齿等),以prevent模糊骨形态发生蛋白。和照顾非最佳的色彩/格式/ DPI设置上BitmapOptions /画布/ SurfaceViews,甚至窗户。

But beware as some bitmap loading methods are a bit buggy and create 'the bmp is too big for the VM' errors. Also learn to dispose of your bmps properly; a lot of people and Google/Googlers say Android does this and you don't have to set your bmps to null and recycle() them, but so far I've found that you do. Another caveat is to set the proper options (filtering/antialiasing etc) to prevent blurry bmps. And take care of un-optimal color/format/dpi settings on BitmapOptions/canvasses/SurfaceViews and even windows.

还有很多,但这应该帮助任何人上手。

There's much more, but this should help anyone get started.

这篇关于安卓游戏所有的屏幕尺寸工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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