我正在为一个按钮编写一个类。这个想法是按钮计算文本的大小,然后相应地缩放它自己。
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);这段代码运行得很好。
我正在使用BoundingBoxes检查冲突。但是,如何在创建边界框时考虑比例毒害?
到目前为止,我有:
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));但碰撞发生在离按钮数英里的地方
提前谢谢。
发布于 2013-08-28 04:36:43
根据您的比例变换边界框:
scaledBounds = new BoundingBox(bounds.Min * Scale, bounds.Max*Scale)https://stackoverflow.com/questions/18473611
复制相似问题