omniGames

I'm working on a particle system. While experimenting, I created some scale and rotation tests to make sure the particle system is working as expected. For these tests, I am using both positive and negative values for both the scale and rotation factors.

With rotation, a positive value rotates the sprite clockwise and a negative value rotates the sprite counterclockwise. That's fine.

I then tried scaling. When I increased the scale factor, the sprite enlarged as expected. However, when I decreased the scale factor, the sprite shrank but ONLY WHILE THE SCALE FACTOR WAS POSITIVE. As soon as the scale factor became negative, the sprite began to enlarge again! In mathematical terms, it appears the sprite is using the Absolute Value of the scale factor rather than the actual value itself. (For negative values, I would expect the sprite to disappear altogether.)

Is this a bug with SpriteBatch.Draw or by design I couldn't find any information on why this should be. Specifically, I'm using the signature outlined at http://msdn2.microsoft.com/en-us/library/bb196416.aspx

I can of course check this myself by not scaling if the scale factor is negative. But enlarging the sprite using a negative value seems counterintuitive.

### Re: XNA Game Studio Express Bug with SpriteBatch.Draw scale?

minahito

Hi omniGames,

I think that's not bug. Many existing engines and libraries have the same policy as XNA about scaling.

Negative values may reverse points for AXIS. But, normally, -2 doesn't equal 0.5.

(2, 2) * 2 = (4, 4)
(2, 2) * -2 = (-4, -4)

I don't know XNA detail, but I often use negative values for scaling to reverse points.

If you hope that negative values scale down textures, inverse functions may be good.

scale = (scale < 0) (-1 / scale) : scale;

### Re: XNA Game Studio Express Bug with SpriteBatch.Draw scale?

Brandon Bloom

This is not a bug, this is the correct mathematical behavior and is actually very useful for reflections as minahito pointed out.

"It includes also the case that one or more scale factors are equal to zero (projection), and the case of one or more negative scale factors. The latter corresponds to a combination of scaling proper and a kind of reflection"