从 spritesheet 绘制 sourcerectangle 似乎不起作用(Monogame)

Drawing a sourcerectangle from a spritesheet doesn't seem to work (Monogame)

已解决

我正在使用 monogame 制作基本的 2D 平台游戏。到目前为止没有太多问题,绘制整个 spritesheet 没问题。

我想添加 运行 动画,知道每个精灵的宽度为 41 像素,高度为 54 像素,我将这些尺寸的源矩形和正确的位置传递给绘制函数。由于某种原因,它现在不再绘制任何东西了。

这是我原来的 Draw 函数,它确实有效:

public virtual void Draw()
{
    if(sprite != null)
    {
        Globals.spriteBatch.Draw(sprite, new Rectangle((int)pos.X, (int)pos.Y, (int)dims.X, (int)dims.Y), null, Color.White, 0.0f, new Vector2(sprite.Bounds.Width / 2, sprite.Bounds.Height / 2), SpriteEffects.None, 0);
    }
}

这是源矩形不起作用的那个:

public virtual void Draw(Rectangle frame)
{
    if (sprite != null)
    {
        Globals.spriteBatch.Draw(sprite, new Rectangle((int)pos.X, (int)pos.Y, (int)dims.X, (int)dims.Y), frame, Color.White, 0.0f, new Vector2(sprite.Bounds.Width / 2, sprite.Bounds.Height / 2), SpriteEffects.None, 0);
    }
}

它由播放器中覆盖的绘制函数调用class:

public override void Draw()
{
    base.Draw(new Rectangle(frame * 41, 0, 41, 54));
}

frame 变量每帧使用以下公式更新:

frame = (frame + 1) % 4;

我忘记更新矩形的尺寸了。它与源矩形本身无关。