MonoGame / VS - PNG 作为 Texture2D 显示为错误的颜色?

MonoGame / VS - PNG as Texture2D displaying as wrong color?

我在 Visual Studio 2019 年 Mac 使用 MonoGame。 我正在按照这个 Microsoft tutorial 制作一个 iOS 小程序,其中一个角色会走向您触摸的任何地方。

我完成了教程并且一切正常,但是他们提供的 spritesheet 中的字符在 iPhone 11 模拟器的高分辨率显示器上很小,所以我想把它做得更大。 我打开 VSCode 并使用“Image Resizer”扩展将宽度和高度加倍。 Here are the two spritesheets for comparison—我只使用了每个的第一行。

然后我返回完整 Visual Studio 并将其添加到项目中,因此图像的两个版本都在“内容”文件夹中。

我对实际代码所做的唯一调整是:1) 将文件名从 charactersheet.png 更改为 charactersheetbigger.png; 2) 调整用于每一帧动画的 Rectangle 的坐标,将它们加倍或保持原样。

当我 运行 更新程序时,精灵的形状和动画显示正确,但令我惊讶的是,一切都有蓝色调。当我恢复使用原始文件和原始坐标时,一切正常。当我使用双倍坐标但使用较小的 spritesheet 时,颜色是正确的。 Here are screenshots of all three variations.

鉴于此,问题似乎一定出在它如何加载更大的 spritesheet 上,但我所做的只是调整它的大小,所以我不明白为什么会这样。

Here are images 文件在解决方案资源管理器中的位置以及 Finder 中两个图像的“获取信息”页面的并排比较。

下面是来自 CharacterEntity 构造函数的代码,其中包含更改后的代码以及实际绘制它的方法。我知道在角色构造函数中对动画进行排序是不雅的,但教程就是这样做的。

    public class CharacterEntity
    {
        static Texture2D characterSheetTexture;

        public CharacterEntity(GraphicsDevice graphicsDevice)
        {
            if (characterSheetTexture == null)
            {
                // using (var stream = TitleContainer.OpenStream("Content/charactersheet.png"))
                using (var stream = TitleContainer.OpenStream("Content/charactersheetbigger.png"))
                {
                    characterSheetTexture = Texture2D.FromStream(graphicsDevice, stream);
                }
            }

            walkDown = new Animation();
            walkDown.AddFrame(new Rectangle(0, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkDown.AddFrame(new Rectangle(32, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkDown.AddFrame(new Rectangle(0, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkDown.AddFrame(new Rectangle(64, 0, 32, 32), TimeSpan.FromSeconds(.25));

            walkUp = new Animation();
            walkUp.AddFrame(new Rectangle(288, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkUp.AddFrame(new Rectangle(320, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkUp.AddFrame(new Rectangle(288, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkUp.AddFrame(new Rectangle(352, 0, 32, 32), TimeSpan.FromSeconds(.25));

            walkLeft = new Animation();
            walkLeft.AddFrame(new Rectangle(96, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkLeft.AddFrame(new Rectangle(128, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkLeft.AddFrame(new Rectangle(96, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkLeft.AddFrame(new Rectangle(160, 0, 32, 32), TimeSpan.FromSeconds(.25));

            walkRight = new Animation();
            walkRight.AddFrame(new Rectangle(192, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkRight.AddFrame(new Rectangle(224, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkRight.AddFrame(new Rectangle(192, 0, 32, 32), TimeSpan.FromSeconds(.25));
            walkRight.AddFrame(new Rectangle(256, 0, 32, 32), TimeSpan.FromSeconds(.25));

            standDown = new Animation();
            standDown.AddFrame(new Rectangle(0, 0, 32, 32), TimeSpan.FromSeconds(.25));

            standUp = new Animation();
            standUp.AddFrame(new Rectangle(288, 0, 32, 32), TimeSpan.FromSeconds(.25));

            standLeft = new Animation();
            standLeft.AddFrame(new Rectangle(96, 0, 32, 32), TimeSpan.FromSeconds(.25));

            standRight = new Animation();
            standRight.AddFrame(new Rectangle(192, 0, 32, 32), TimeSpan.FromSeconds(.25));
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            Vector2 topLeftOfSprite = new Vector2(this.X, this.Y);
            Color tintColor = Color.White;
            var sourceRectangle = currentAnimation.CurrentRectangle;
            spriteBatch.Draw(characterSheetTexture, topLeftOfSprite, sourceRectangle, tintColor);
        }

我已经在互联网上进行了梳理,但还没有找到其他人遇到这个确切的问题。我看到有些人根本无法加载 png,作为回应,我看到有些人建议使用 MonoGame 的内容管道将 png 转换为 xnb,但我不知道该怎么做,以及当我的代码 是否与 原始 png 一起工作,似乎必须有一个更简单的解决方案,或者至少解释为什么会发生这种情况。

有什么想法吗?很高兴根据需要分享更多详细信息。

我解决了问题!

这一定与我调整图像大小有关。我通过在 Photoshop 中打开原始的、较小的 spritesheet 来修复它,在那里调整它的大小,然后使用那个版本。如果有人对 为什么 这行得通有任何建议,我很乐意理解。