In Xna a spritebatch can be passed a value for scale. I have A bounding box Rectangle that i have a border drawn around my sprite using the bounding box rect.

Now my question Scale can make the sprite go up just fine,but how can i get the bounding box rect to scale up with the scale propertie?

  • 1
    \$\begingroup\$ Are you looking to uniformly scale? i.e: the whole box increases by a factor of two around the origin? \$\endgroup\$ Feb 7, 2013 at 3:54

1 Answer 1


Just adjust the size of the bounding box to factor in the scale.


Rectangle boundingBox = new Rectangle(texture.Width * scaleX, texture.Height * scaleY)

texture refers to the Texture2D instance of your image. scaleX and scaleY are the horizontal and vertical scaling components respectively, with the trivial case of scaleX = scaleY when you scale uniformly.

Edit: if the origin of the image is not the default (top-left corner), you should also adjust your rectangle by the origin point.

  • \$\begingroup\$ This only works if origin is at.. the top left. \$\endgroup\$ Feb 7, 2013 at 4:45
  • \$\begingroup\$ @VaughanHilts updated slightly. The default is the top-left at any rate. \$\endgroup\$
    – ashes999
    Feb 7, 2013 at 4:48
  • \$\begingroup\$ i still have a problem when I tried this before i posted this question but when I multiply scale * texture scale is a float so when I cast it to a int it gets 1.9999999 .I don't no why this is happening \$\endgroup\$
    – koss
    Feb 7, 2013 at 5:50
  • \$\begingroup\$ @koss If this helped you out, make sure to mark this as the answer. \$\endgroup\$ Feb 7, 2013 at 12:02
  • 1
    \$\begingroup\$ @koss float are represented via the equation (Significant digits × base ^ exponent). Unfortunately that can only represent a finite number on values so when you tell it to represent a value that is impossible to represent (2.0) it gives you closest value it can represent (1.999999). \$\endgroup\$ Feb 7, 2013 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .