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