使用小于零的Vector2缩放图像

时间:2016-06-29 02:40:28

标签: c# collision-detection monogame rectangles

我目前正在开展一个项目,而且我正试图缩小图像。 我有一个由以下代码确定的命中箱。

public Rectangle bound
    {
        get
        {
            return new Rectangle((int)position.X, (int)position.Y, 
                texture.Width * (int)scale.X,
                texture.Height * (int)scale.Y);
        }
    }

这可以假设比例是一个或更大。但是,当我输入小于一次碰撞的比例值时,并且Console.WriteLine()函数返回{X:300 Y:300宽度:0高度:0}。 我有什么不对的吗?

1 个答案:

答案 0 :(得分:1)

我不觉得傻。

public Rectangle bound
    {
        get
        {
            return texture == null ? new Rectangle(0,0,0,0) : new Rectangle((int)position.X, (int)position.Y,
                (int)(texture.Width * scale.X), (int)(texture.Height * scale.Y));
        }
    }

显然,如果矩形的尺寸是浮点数,则返回零。