【发布时间】:2018-10-12 13:21:52
【问题描述】:
我正在使用 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;
}
谢谢!
【问题讨论】:
标签: c# matrix camera sprite monogame