在 XNA 中缩放整个屏幕
我正在尝试使用 XNA 制作一个冒险游戏引擎,让您制作出看起来像是 90 年代早期的游戏,例如 Day of the Tentacle 和 Sam & Sam。麦克斯上路了。。因此,我希望游戏实际以 320x240 运行(我知道,它可能应该是 320x200,但是嘘),但它应该根据用户设置进行缩放。
它现在工作得还不错,但我遇到了一些问题,我实际上希望它看起来比当前更像素化。
这就是我现在正在做的事情:
在游戏初始化中:
public Game() {
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 640;
graphics.PreferredBackBufferHeight = 480;
graphics.PreferMultiSampling = false;
Scale = graphics.PreferredBackBufferWidth / 320;
}
Scale 是一个公共静态变量,我可以随时检查它以查看相对于 320x240 应该将游戏缩放多少。
在我的绘图函数中:
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.CreateScale(Game.Scale));
这样,所有内容都以 320x240 绘制,并放大以适合当前分辨率(默认为 640x480)。当然,我会进行数学运算,将鼠标的实际坐标转换为 320x240 坐标,依此类推。
现在,这一切都很棒,但现在我想要开始缩放我的精灵,让它们走到远处等等。
看看下面的图片。左上图是游戏以 640x480 运行时的屏幕截图。右边的图像是它“应该”的样子,分辨率为 320x240。底行图像只是将顶行放大到 300%(在 Photoshop 中,而不是在引擎中),因此您可以看到我在说什么。
在 640x480 图像中,您可以看到不同的“线条粗细”;较粗的线条是它真正的样子(一个像素 = 2x2,因为这是在 640x480 下运行),但较细的线条(1x1 像素)也会出现,但由于缩放,它们不应该出现(请参见右侧的图像) )。
基本上,我试图模拟 320x240 显示器,但使用 XNA 放大到任何分辨率,而矩阵转换并不能解决问题。我有什么办法可以做到这一点吗?
Using XNA, I'm trying to make an adventure game engine that lets you make games that look like they fell out of the early 90s, like Day of the Tentacle and Sam & Max Hit the Road. Thus, I want the game to actually run at 320x240 (I know, it should probably be 320x200, but shh), but it should scale up depending on user settings.
It works kind of okay right now, but I'm running into some problems where I actually want it to look more pixellated that it currently does.
Here's what I'm doing right now:
In the game initialization:
public Game() {
graphics = new GraphicsDeviceManager(this);
graphics.PreferredBackBufferWidth = 640;
graphics.PreferredBackBufferHeight = 480;
graphics.PreferMultiSampling = false;
Scale = graphics.PreferredBackBufferWidth / 320;
}
Scale is a public static variable that I can check anytime to see how much I should scale my game relative to 320x240.
In my drawing function:
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.CreateScale(Game.Scale));
This way, everything is drawn at 320x240 and blown up to fit the current resolution (640x480 by default). And of course I do math to convert the actual coordinates of the mouse into 320x240 coordinates, and so forth.
Now, this is great and all, but now I'm getting to the point where I want to start scaling my sprites, to have them walk into the distance and so forth.
Look at the images below. The upper-left image is a piece of a screenshot from when the game is running at 640x480. The image to the right of it is how it "should" look, at 320x240. The bottom row of images is just the top row blown up to 300% (in Photoshop, not in-engine) so you can see what I'm talking about.
In the 640x480 image, you can see different "line thicknesses;" the thicker lines are how it should really look (one pixel = 2x2, because this is running at 640x480), but the thinner lines (1x1 pixel) also appear, when they shouldn't, due to scaling (see the images on the right).
Basically I'm trying to emulate a 320x240 display but blown up to any resolution using XNA, and matrix transformations aren't doing the trick. Is there any way I could go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以原始分辨率将所有内容渲染到 RenderTarget 而不是后台缓冲区:
然后将此目标(整个屏幕)渲染到后台缓冲区:
Render everything in the native resolution to a RenderTarget instead of the back buffer:
Then render this target (your whole screen) to the back buffer: