1
votes

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.

1
The line (location.Y + buttonTexture.Height) * scale.Y seems strange to me, shouldn't it be location.Y + buttonTexture.Height * scale.Yjrbeverly
Thanks for the answer. all Works! :Duser1662290

1 Answers

0
votes

Transform the boundingbox by your scale:

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