But possibly a better method than scaling each sprite (as you'd also have to scale the position of each sprite) is to just pass a matrix to SpriteBatch.Begin, like so:sb.Begin(/* first three parameters */, Matrix.CreateScale(4f));这将为您提供所需的缩放比例,而无需修改所有绘制调用.That will give you the scaling you want without having to modify all your draw calls.但是值得注意的是,如果您在游戏中使用浮点偏移,那么在您放大(使用任何一种方法)后,最终都会出现与像素边界不对齐的情况.However it is worth noting that, if you use floating-point offsets in your game, you will end up with things not aligned to pixel boundaries after you scale up (with either method).对此有两种解决方案.第一个是有这样的功能:There are two solutions to this. The first is to have a function like this:public static Vector2 Floor(Vector2 v){ return new Vector2((float)Math.Floor(v.X), (float)Math.Floor(v.Y));}然后在每次绘制精灵时通过该函数传递您的位置.尽管如果您的精灵使用任何旋转或偏移,这可能不起作用.您将再次修改每个绘图调用.And then pass your position through that function every time you draw a sprite. Although this might not work if your sprites use any rotation or offsets. And again you'll be back to modifying every single draw call.正确"这样做的方法是,如果您想要对整个场景进行简单的逐点放大,则是以原始大小将场景绘制到渲染目标.然后将渲染目标绘制到屏幕上,放大(使用 TextureFilter.Point).The "correct" way to do this, if you want a plain point-wise scale-up of your whole scene, is to draw your scene to a render target at the original size. And then draw your render target to screen, scaled up (with TextureFilter.Point).您要查看的函数是GraphicsDevice.SetRenderTarget.这篇 MSDN 文章 可能值得一读.如果您正在使用或转向 XNA 4.0,这可能值得一读.The function you want to look at is GraphicsDevice.SetRenderTarget. This MSDN article might be worth reading. If you're on or moving to XNA 4.0, this might be worth reading.我找不到一个更简单的 XNA 示例,但是 Bloom Postprocess 示例使用渲染目标,然后对其应用模糊着色器.您可以简单地完全忽略着色器并进行放大.I couldn't find a simpler XNA sample for this quickly, but the Bloom Postprocess sample uses a render target that it then applies a blur shader to. You could simply ignore the shader entirely and just do the scale-up. 这篇关于如何缩放屏幕像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 21:31
查看更多