C# 调整大小的雪碧不';t显示

C# 调整大小的雪碧不';t显示,c#,xna,C#,Xna,我试图根据屏幕高度调整图像大小,但遇到了麻烦。目前的问题是图像根本不显示。代码如下: class Board { private Texture2D texture; private int screenWidth = Game1.Instance.GraphicsDevice.Viewport.Width; private int screenHeight = Game1.Instance.GraphicsDevice.Viewport.Height; priv

我试图根据屏幕高度调整图像大小,但遇到了麻烦。目前的问题是图像根本不显示。代码如下:

class Board
{
    private Texture2D texture;
    private int screenWidth = Game1.Instance.GraphicsDevice.Viewport.Width;
    private int screenHeight = Game1.Instance.GraphicsDevice.Viewport.Height;
    private Vector2 location;
    private Rectangle destination;

    public Board(Texture2D texture)
    {
        this.texture = texture;
        this.location = new Vector2(200, 0);
        this.destination = new Rectangle((int)location.X, (int)location.Y, texture.Width * (screenHeight / texture.Height), screenHeight);
    }

    public void Draw(SpriteBatch spriteBatch)
    {
        spriteBatch.Begin();
        spriteBatch.Draw(texture,
                        destination,
                        Color.White);
        spriteBatch.End();
    }
}
该图像以前已经显示过,但仍然太宽,因此我知道主循环中的代码很好。总之,我的问题是。。。这段代码有什么问题,有没有更好的方法

texture.Width * (screenHeight / texture.Height)
正在使用整数除法。如果纹理大于屏幕,它将返回0。宽度为0时,将看不到纹理。相反,将一个操作数强制转换为
双精度
浮点

texture.Width * (screenHeight / (double)texture.Height)

将返回一个
双精度
,允许除法/乘法按预期工作。

成功了!非常感谢你!没问题。整数除法,特别是在处理框架类时,可能很难识别。我已经编辑了你的标题。请参阅“”,其中的共识是“不,他们不应该”。