C# xna矩阵相机2d在使用点箝位时具有额外像素

C# xna矩阵相机2d在使用点箝位时具有额外像素,c#,matrix,xna,sprite,monogame,C#,Matrix,Xna,Sprite,Monogame,我有一个在矩阵上编程的相机,但是当使用矩阵设置比例时,精灵有时渲染模糊,我使用点夹,因为我希望它们显示像素。如果我将缩放写入精灵的绘制方法,效果就很好。我有代码,因此矩阵如下所示: this._transform = Matrix.CreateTranslation( new Vector3( -( this._position.X * 100 ), -(this._position.Y * 100), 0 ) ) * Matrix.CreateRotationZ( this._rotation

我有一个在矩阵上编程的相机,但是当使用矩阵设置比例时,精灵有时渲染模糊,我使用点夹,因为我希望它们显示像素。如果我将缩放写入精灵的绘制方法,效果就很好。我有代码,因此矩阵如下所示:

this._transform = Matrix.CreateTranslation(
new Vector3( -( this._position.X * 100 ), -(this._position.Y * 100), 0 ) ) *
Matrix.CreateRotationZ( this._rotation ) *
Matrix.CreateScale( this._worldSize.Z, this._worldSize.Z, 1f ) *
Matrix.CreateTranslation( new Vector3( this._atlas.GetViewport().GetViewportWidth() * 0.5f, this._atlas.GetViewport().GetViewportHeight() * 0.5f, 0 ) );
我的绘图代码和注释掉的手动缩放

float zoomLevel = camera.GetWorldViewSize().Z;
Rectangle viewPosition = new Rectangle();
Vector2 viewWorldPosition = new Vector2( worldPosition.position.X, worldPosition.position.Y );
viewPosition.X = (int)(( Math.Round( viewWorldPosition.X ) ) /* + ( viewWorldPosition.X * zoomLevel ) */ );
viewPosition.Y = (int)(( viewWorldPosition.Y ) /* + ( viewWorldPosition.Y * zoomLevel ) */ );
viewPosition.Y = -viewPosition.Y;
viewPosition.X -= (int)( ( drawSettings.spritePosition.Width * drawSettings.anchor.X ) /* * zoomLevel */ );
viewPosition.Y -= (int)( ( drawSettings.spritePosition.Height * drawSettings.anchor.Y ) /* * zoomLevel */ );
viewPosition.Width = (int)( drawSettings.spritePosition.Width /* * zoomLevel */ );
viewPosition.Height = (int)( drawSettings.spritePosition.Height /* * zoomLevel */ );
spriteBatch.Draw(
  drawSettings.image.GetTexture(),
  viewPosition,
  drawSettings.spritePosition,
  drawSettings.imageTint,
  0,
  Vector2.Zero,
  drawSettings.flip,
  (float)( this._drawDepth.zIndex / 1000 )
);
我已经读到,这可能是因为xna绘制放大的精灵时的插值造成的。有没有办法把它关掉,我已经试过几次了。我在sprite批处理创建中有以下内容

GraphicsDevice.SamplerStates[0].MaxAnisotropy = 0;
GraphicsDevice.SamplerStates[0].Filter = TextureFilter.Point;
我还使用以下参数设置了图形设备

graphics = new GraphicsDeviceManager( this );
graphics.SynchronizeWithVerticalRetrace = true;
graphics.PreferMultiSampling = false;
graphics.CreateDevice();
Core.Application.graphicsDevice = graphics.GraphicsDevice;
graphics.IsFullScreen = false;
graphics.GraphicsDevice.PresentationParameters.IsFullScreen = false;
graphics.GraphicsDevice.PresentationParameters.BackBufferFormat = SurfaceFormat.Color;
graphics.GraphicsDevice.PresentationParameters.MultiSampleCount = 0;
graphics.GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents; 
graphics.GraphicsDevice.PresentationParameters.PresentationInterval = PresentInterval.Immediate;
graphics.GraphicsDevice.PresentationParameters.DepthStencilFormat = DepthFormat.Depth24Stencil8;
graphics.GraphicsDevice.PresentationParameters.BackBufferWidth = graphics.PreferredBackBufferWidth;
graphics.GraphicsDevice.PresentationParameters.BackBufferHeight = graphics.PreferredBackBufferHeight;
graphics.GraphicsDevice.Viewport = new Microsoft.Xna.Framework.Graphics.Viewport( 0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight );
任何帮助我都会尝试,任何建议我都会使用。我想使用矩阵进行缩放,因为它使数学更容易阅读,而不是在代码中。如果这是不可能的,我有手动缩放工作,如我所述

我不能发表任何关于这方面的图片,但我可以参考其他类似的问题,因为问题的性质得到图片将是非常困难的


手动在GraphicsDevice上设置SamplerState对SpriteBatch没有好处,因为调用End()调用后,在为精灵发出draw调用之前(假设您没有使用Immediate进行渲染),该状态和其他几个GraphicsDevice状态将被覆盖

将所需状态作为SamplerState对象传递给SpriteBatch的Begin()重载之一。有现成的SamplerState.PointClamp,也可以创建自己的


如果要自己在开始/结束对内设置或更改采样器状态(或混合、深度模具或光栅化器状态),则必须使用立即模式,该模式在开始调用时仅设置一次图形状态。但是你会对你画的每一个精灵进行一次绘制调用。

我已经使用即时模式设置了它,但没有效果。在我的SpriteBatch中,我确实将SamplerState设置为PointClamp。对于导致问题的对象,它们可以正确缩放,但是,当每隔一段时间移动一次时,会有额外的像素,使它们在快速移动位置时看起来模糊。只有当我在相机矩阵中设置了缩放时才会发生这种情况。@navstev0您看到这个问题的目标平台是什么?原生XNA?单游戏WindowsGL?MonoGame还有别的吗?MonoGame Visual Studio构建。你的代码太离题了,我无法直接使用,所以我尝试使用我自己的一款基于tileset的游戏。我在引擎中手动缩放所有内容,但我将其改为进行矩阵缩放。我无法让它显示出模糊或你的链接中断。让我们确保我们在同一基线上工作。如果您不是从最新的源代码构建MonoGame WindowsGL,请从该源代码开始。