流畅的文字,令人不快的精灵

时间:2018-10-12 13:21:53

标签: c# matrix camera sprite monogame

使用Monogame,我正在制作一款游戏,该游戏将图形和文本同时绘制到屏幕上,并且其位置由相机矩阵修改。如果将文本的位置设置为摄影机的位置,一切都很好,但是当我将精灵设置为摄影机的位置时,随着摄影机的移动会有非常明显的抖动。我认为这是因为图形是用需要整数位置值的矩形绘制的。我想文字没有这样的要求。

如何使我的图形像文字一样平稳地跟随相机的运动?

如果有用,这是我的spriteBatch.Begin()调用:

spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearClamp, null, null, null, camera.GetTransformation(graphics));

这是我的摄像头转换:

public Matrix GetTransformation(GraphicsDeviceManager graphicsDevice)
        {
            Vector3 newVector = new Vector3(-GameInfo.info.cameraPosition.X, -GameInfo.info.cameraPosition.Y, 0);

            cameraTransformMatrix = Matrix.CreateTranslation(newVector) *
                                    Matrix.CreateRotationZ(rotation) *
                                    Matrix.CreateScale(new Vector3(zoom, zoom, 1)) *
                                    Matrix.CreateTranslation(new Vector3(GameInfo.info.resolutionWidth * 0.5f, GameInfo.info.resolutionHeight * 0.5f, 0));

            return cameraTransformMatrix;
        }

谢谢!

1 个答案:

答案 0 :(得分:0)

我设法通过使用不依赖于目标矩形的SpriteBatch.Draw()不同的重载来解决该问题:

spriteBatch.Draw(texture, position, rSpriteSourceRectangle, Color.White);

作为参考,这是我的老照片:

spriteBatch.Draw(texture, new Rectangle(drawX, drawY, frameWidth, frameHeight), rSpriteSourceRectangle, Color.White);
相关问题