I am working on a class for a button. The idea is that the button calculates the size of the text and then scale itself accordingly.
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);
This code works great.
I am using BoundingBoxes to check the collision. However, how do I take into account the scale poistion when creating the bounding box?
So far I have:
BoundingBox buttonBox = new BoundingBox(new Vector3(location, 0), new Vector3(location.X + buttonTexture.Width, location.Y + buttonTexture.Height, 0));
I've tried multiplying the lower-right point of the boundingbox by the scale:
BoundingBox buttonBox = new BoundingBox(new Vector3(location, 0), new Vector3((location.X + buttonTexture.Width * scale.X), (location.Y + buttonTexture.Height) * scale.Y, 0));
But the collision was occurring miles from the button
Thanks in advance.
(location.Y + buttonTexture.Height) * scale.Y
seems strange to me, shouldn't it belocation.Y + buttonTexture.Height * scale.Y
– jrbeverly