0
\$\begingroup\$

I'm having interesting problem with rotating a sprite in MonoGame. Here is how origin, destination rectangle and scale are created:

  Vector2 origin = new Vector2(tx.Width / 2, tx.Height / 2);

  Rectangle dstRectangle = new Rectangle((int)e.Xpos, (int)e.Ypos, (int)(tx.Width), (int)(tx.Height));
        dstRectangle.X += (tx.Width / 2);
        dstRectangle.Y += (tx.Height / 2);

  Vector2 scale = new Vector2(tx.Width * (float)TxScaleFactor, tx.Height * (float)TxScaleFactor);

And here is the draw function:

 Editor.spriteBatch.Draw(texture: GlowWhite, destinationRectangle: dstRectangle, color: Tint * (Alpha * 0.6f), rotation: rotation, scale: scale, origin: origin);

Now, with angle 0.0f, everything is fine but any additional rotations become weird:

  1. Zero rotation, white background is WinForms picturebox, below is MonoGame enter image description here

  2. 90 deg

enter image description here

  1. And 180 deg

enter image description here

Its like there is some kind of offset - I've tried to change 0 to 90, and back 0 and next to 180 - result is always the same (apparently, there is no adding). I'm guessing that problem is related to origin, destination rectangle or scale. Sprites are rotated in place as you can see (no issues with that) but something with rotation isn't right. Any ideas?

\$\endgroup\$
2
\$\begingroup\$

Nevermind, my (poor) experience in graphics is problem - rotation has to be in radians, not degrees. Solution is MathHelper.ToRadians(rotationInDeg)...

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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