【问题标题】:Scaling an image with a Vector2 less than zero缩放 Vector2 小于零的图像
【发布时间】:2016-06-29 02:40:27
【问题描述】:

我目前正在处理一个项目,我正在尝试缩小图像。 我有一个由以下代码确定的命中框。

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

假设比例为 1 或更大,则此方法有效。但是,当我输入小于一个的比例值时,冲突不起作用,并且 Console.WriteLine() 函数返回 {X:300 Y:300 Width:0 Height:0}。 是不是我做错了什么?

【问题讨论】:

  • 转换为int 会截断,所以0.9 会转换为0。尝试在 after 乘法之后转换:(int)(texture.Width * scale.X)
  • 在我看到你的评论之前就想通了。谢谢。

标签: c# collision-detection monogame rectangles


【解决方案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));
        }
    }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    相关资源
    最近更新 更多