anistropic

how can i stop my sprite shrinking on the x axis when i rotate it

Re: XNA Game Studio Express 2d sprite shrinks on x axis

Robin Debreuil

It shouldn't be rotating unless you are also setting the width and height on it after rotation For a sprite that has zero at the top left you can use something like:

float cosA = (float)Math.Cos(rotation);
float sinA = (float)Math.Sin(rotation);
float w = -halfWidth; // move to center
float h = -halfHeight;
float x1 = w * cosA - h * sinA; // rotate
float y1 = h * cosA + w * sinA;

drawRect.X = (int)(xPos + x1 + halfWidth);
drawRect.Y = (int)(yPos + y1 + halfHeight);
...
public override void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(spriteImage, drawRect, sourceRect, Color.White, rotation, origin, SpriteEffects.None, 1F);
}


to get the position where you need.




Re: XNA Game Studio Express 2d sprite shrinks on x axis

dagfari

Or you can use a different overload for 'Draw' like;

spriteBatch.Draw(Image, Position, null, Color.White, Rotation, Origin, Scale, SpriteEffects.None, 0);

where Position and Origin are Vector2.

Now you can make the Origin of your sprite the center;

Origin = new Vector2(Image.Width / 2, Image.Height / 2);

...then use Rotate to set the angle (remember it's in Radians)









Re: XNA Game Studio Express 2d sprite shrinks on x axis

Robin Debreuil

Oh nice - didn't know that, thanks!