Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
1  
Are you looking to uniformly scale? i.e: the whole box increases by a factor of two around the origin? –  Vaughan Hilts Feb 7 '13 at 3:54
add comment

1 Answer 1

up vote 1 down vote accepted

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

i.e.

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.

share|improve this answer
    
This only works if origin is at.. the top left. –  Vaughan Hilts Feb 7 '13 at 4:45
    
@VaughanHilts updated slightly. The default is the top-left at any rate. –  ashes999 Feb 7 '13 at 4:48
    
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 –  koss Feb 7 '13 at 5:50
    
i have it working better now thanks –  koss Feb 7 '13 at 6:23
1  
@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). –  ClassicThunder Feb 7 '13 at 14:44
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.