3
\$\begingroup\$

I am drawing a rectangle using a emptytexture (1x1) and I use the following:

spriteBatch.Draw(EmptyTexture, new Rectangle((int)MyPosition.X + MyTexture.Width / 2, (int)MyPosition.Y + MyTexture.Height / 2, 100, 2000), null, Color.Red, MyDirection + MathHelper.ToRadians(180), new Vector2(0, 0), SpriteEffects.None, 0.0f);

which does this: enter image description here enter image description here

But now I am trying to make another rectangle next to that one which looks like this: enter image description here

But when you rotate the ship it rotates like this: enter image description here

I've done this by the following:

spriteBatch.Draw(EmptyTexture, new Rectangle((int)(MyPosition.X + MyTexture.Width / 2) + 100, (int)MyPosition.Y + MyTexture.Height / 2, 100, 2000), null, Color.DarkRed, MyDirection + MathHelper.ToRadians(180), new Vector2(0, 0), SpriteEffects.None, 0.0f);

But what I am trying to do is to make the point of rotation of the 2nd one at the middle of the ship like the other one but it's drawn the same.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Solved

spriteBatch.Draw(EmptyTexture, new Rectangle((int)(MyPosition.X + MyTexture.Width / 2) + 100, (int)MyPosition.Y + MyTexture.Height / 2, 100, 2000), null, Color.DarkRed, MyDirection + MathHelper.ToRadians(180), **new Vector2(0, 0)**, SpriteEffects.None, 0.0f);

I had to change the origin

new Vector2(0, 0) to new Vector2(1, 0)

I have no clue why though

\$\endgroup\$
1
  • \$\begingroup\$ The new vector moves the pivot point the sprite rotates around to the opposite corner. \$\endgroup\$
    – DMGregory
    Commented Aug 1, 2022 at 20:34

You must log in to answer this question.

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