关于屏幕分辨率的问题 [英] Question about screen resolution

查看:80
本文介绍了关于屏幕分辨率的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看,我正在为我的计算机项目制作一个游戏(在XNA 4中)。所以,我在家做编程并在学校的学校计算机上进行测试。我在游戏中的许多点放置了几个对象。示例一些在vector2(500,300),(700,1000)等。所有这些项目完全适合我的家用电脑的屏幕。但我注意到我学校的电脑屏幕较小,所以有些物体没有出现在学校的屏幕上。如何我可以在所有屏幕尺寸上正确准确地显示所有对象吗?请帮助,紧急

See,I'm making a game for my computer project(in XNA 4).So,I do the programming at home and test it on the school computer in school.I placed several objects at many points in my game for example some at vector2(500,300),(700,1000) etc.All these items fit perfectly on my home computer's screen.But I noticed the the computer screen in my school is smaller so some objects do not appear in the school screen.How can I display all objects correctly and accurately on all screen sizes?Please help,its urgent.

推荐答案

你能回复吗?举个例子



假设你的屏幕宽1000像素:



"can you reply with an example"

Assuming your screen is 1000 pixels wide:

int x = 700;                 // BAD!

int x = (WidthOfScreen * 700) / 1000;       // Better!

int xPercent = 70;
int x = (widthOfScreen * xPercent) / 100;   // Best!


"in my game,I have drawn maybe 400-500 objects.Will I have to adjust all of them?It will surely take a lot of time."

你绝对是我们希望找到一个通用解决方案,它将负责扩展你的Window(或任何XNA调用它的显示),以及其中的所有对象。我打赌可以找到。



我想你可能会在XNA程序员的论坛上得到一些帮助。 'DreamInCode似乎非常活跃。快速搜索出现了这个可能的资源:为PC创建独立分辨率:[ ^ ]。

You absolutely will want to find a "general" solution that will take care of scaling your Window (or whatever XNA calls its display), and all the objects in it. I bet that can be found.

I think you probably can get some help on an XNA programmer's forum. 'DreamInCode seems to be a very active one. A quick search turned up this likely resource: "Creating Resolution Independence For PC:" [^].


如果您不熟悉渲染中使用的不同矩阵及其用途,那么我建议您做一些阅读。但一般来说你应该有一个模型矩阵,一个视图矩阵和一个投影矩阵。



模型矩阵表示一个物体在场景中的位置,通常是不同的对于每个被渲染的对象,除非顶点已经在世界空间中(即,不需要转换)。

视图矩阵代表你的相机,所以如果你把相机移到右边那么一切都在场景似乎向左移动。

投影矩阵将您的3D坐标转换为屏幕空间(屏幕上的2D位置)。



如果要在一系列分辨率和宽高比上渲染UI元素,则只需要更新这些矩阵,而不是每个对象。

最简单的方法是将模型和视图矩阵作为标识矩阵,并使用屏幕空间坐标(介于0-1或-1和1之间)定位所有UI元素我不记得XNA使用的内容。



如果你不想拉伸东西,你仍然需要处理宽高比的变化。
If you're not familiar with the different matrices used in rendering and their purpose then I suggest you do some reading. But generally speaking you should have a Model matrix, a View matrix and a Projection matrix.

The Model matrix represents the position of an object in the scene and is usually different for each object being rendered, unless the vertices are already in world space (ie, no transformation is necessary).
The View matrix represents you camera, so if you moved your camera to the right everything in the scene would appear to move left.
The Projection matrix transforms your 3D coordinates into Screen space (the 2D position on your screen).

If you want to render UI elements across a range of resolutions and aspect ratios you only need to update these matrices, instead of every single object.
The easiest way is to have the Model and View matrices as Identity matrices, and position all of your UI elements using screen space coordinates (which are between 0-1, or -1 and 1 I don't remember what XNA uses).

You would still need to handle changes in aspect ratio if you don't want things to be stretched.


这篇关于关于屏幕分辨率的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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