1
我正在爲一個按鈕的類工作。 這個想法是,按鈕計算文本的大小,然後相應地縮放自己。XNA Scale BoundingBox
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));
但碰撞正在發生英里
在此先感謝。
行'(location.Y + buttonTexture.Height)* scale.Y'覺得奇怪,我,它不應該是'location.Y + buttonTexture .Height * scale.Y' – jrbeverly
感謝您的回答。全部作品! :d – user1662290