Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XNA比例边界框_C#_Xna_Bounding Box - Fatal编程技术网

C# XNA比例边界框

C# XNA比例边界框,c#,xna,bounding-box,C#,Xna,Bounding Box,我正在为一个按钮课程工作。 其思想是,按钮计算文本的大小,然后相应地缩放自身 float X = font.MeasureString(text).X; float Y = font.MeasureString(text).Y; float x = 1.0f + (X / buttonTexture.Width); float y = 1.0f + (Y / buttonTexture.Height); scale = new Vector2(x,y); 这段代码非常有效 我正在使用边界框检查

我正在为一个按钮课程工作。 其思想是,按钮计算文本的大小,然后相应地缩放自身

float X = font.MeasureString(text).X;
float Y = font.MeasureString(text).Y;
float x = 1.0f + (X / buttonTexture.Width);
float y = 1.0f + (Y / buttonTexture.Height);
scale = new Vector2(x,y);
这段代码非常有效

我正在使用边界框检查碰撞。但是,在创建边界框时,如何考虑比例泊松

到目前为止,我已经:

BoundingBox buttonBox = new BoundingBox(new Vector3(location, 0), new Vector3(location.X  + buttonTexture.Width, location.Y  + buttonTexture.Height, 0));
我尝试将边界框的右下角点乘以比例:

BoundingBox buttonBox = new BoundingBox(new Vector3(location, 0), new Vector3((location.X  + buttonTexture.Width * scale.X), (location.Y  + buttonTexture.Height) * scale.Y, 0));
但碰撞发生在离按钮几英里的地方


提前感谢。

按比例变换边界框:

  scaledBounds = new BoundingBox(bounds.Min * Scale, bounds.Max*Scale)

行位置.Y+buttonTexture.Height*scale.Y对我来说似乎很奇怪,是不是应该是location.Y+buttonTexture.Height*scale.YThanks作为答案。一切顺利!:D