【问题标题】:Smooth text, jittery sprites平滑的文本,抖动的精灵
【发布时间】: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


    【解决方案1】:

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

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

    作为参考,这是我以前的:

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

    【讨论】:

    • 我假设您使用 Vector2 进行定位,这很好,因为 Vector2 在定位方面比使用矩形更准确。
    猜你喜欢
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多