WP7 XNA 游戏:如何适应不同的手机分辨率? [英] WP7 XNA game: how to adapt to different phone resolutions?

查看:38
本文介绍了WP7 XNA 游戏:如何适应不同的手机分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一款以 800 x 480 分辨率为目标的游戏,但对让它适应其他 WP7 分辨率感兴趣.此外,我听说可以通过 Mono 和 ExEn 将游戏移植到 iPhone 和 Android,从而打开大量其他屏幕分辨率.

I've created a game that targets the 800 x 480 resolution, but have become interested in having it adapt to other WP7 resolutions. Also, I've heard that games can be ported to iPhone and Android through Mono and ExEn, opening up a ton of other screen resolutions.

处理这个问题的正确方法是什么?我想让游戏足够智能以检测屏幕尺寸并更改资产以使其看起来尽可能接近原始版本并玩相同的游戏.

What is the proper way to deal with this? I'd like to make the game smart enough to detect the screen size and alter the assets to look as close to the original as possible and play the same.

这是一款 2D 游戏,我认为理想的情况是为所有分辨率提供单独的图像,但为了面向未来,这行不通.我想过有一个 800 x 480 的基线,在开始时检测大小,并改变我所有实体的边界以进行缩放,然后简单地将纹理绘制到这些目标.这将使我能够正确地进行碰撞检测并缩放纹理,但可能有更好的方法.

This is a 2D game and I would think the ideal would be to have separate images for all resolutions, but to be future-proof this wouldn't work. I've thought of having a baseline of 800 x 480, detecting size at start, and altering the Bounds of all my entities to scale, then simply draw the textures to those targets. This would allow me to do my collision detection correctly as well as scale the textures, but there is likely a better way.

无论如何,我希望我已经清楚地解释了这个问题.如果没有,我会在评论进来后编辑问题.

Anyway, I hope I have explained the issue clearly. If not, I will edit the question after comments come in.

感谢您的意见.

推荐答案

为了在 Windows Phone 可能支持多种分辨率(或寻找此答案以编写真正的多分辨率引擎)时登陆这里的人们的利益,这就是我做.

For the benefit of people who land here when Windows Phone might support multiple resolutions (or looking for this answer to write true multi-resolution engines), this is how I do it.

我列举/检查了可用的分辨率,并使用我已经知道的纵横比为分辨率设置了正交投影.为此,我硬编码了一张我测试过的游戏的纵横比表,以及每个纵横比的参考"宽度/高度.然后我查看当前请求的分辨率,找到它的纵横比并查看我的表格中最接近较低匹配的纵横比并设置正射投影(居中 - 因此如果高度匹配但宽度不匹配,反之亦然,字母- 自动发生装箱)和相应的视口.

I enumerate/check the available resolutions and set up orthographic projections for resolutions with aspect ratios that I know already. To this end, I hard-code a table of aspect ratios I have tested my game on and the "reference" widths/heights for each of these aspect ratios. I then look at the current requested resolution, find its aspect ratio and look through my table for the closest-lower matched aspect ratio and set up an ortho projection (centered - so if height matches but width doesn't or vice-versa, letter-boxing automatically happens) and viewport accordingly.

例如:我为 qHD (960x540)、WXGA (1280x720) 和 FHD (1920x1080) 设置了 1280x720 的正射投影,因为它们三者具有相同的纵横比.

For example: I'd set up an ortho projection of 1280x720 for qHD (960x540), WXGA (1280x720) and FHD (1920x1080) because all three of them have the same aspect ratio.

在纵横比为 1.5 的 SVGA 和 DVGA (960x640) 显示器上,我会设置 SVGA 800x600 分辨率,以便一切正常.

On both SVGA and DVGA (960x640) display with aspect 1.5, I would set up SVGA 800x600 resolution so everything looks ok.

上述方法可确保如果您针对主要目标设备使用的宽高比设计资产,则它们不会看到任何挤压.请注意,此方法不能用于确定资产的实际分辨率.

The above method makes sure that if you design your assets for the aspect ratios your main target devices use, they will not see any squashing. Note that this method is NOT for determining the actual resolution of your assets.

这篇关于WP7 XNA 游戏:如何适应不同的手机分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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