I’m drawing a rectangle in real time from a 1 x 1 pixel (stretching it). Everything works great EXCEPT it’s not rotating around the point I want. Apparently, there’s something weird about rotating a rectangle (as opposed to rotating a sprite). Here’s what I’ve got happening:
And here’s the code that creates it:
Vector2 end = new Vector2 (BlueArmy[DisplayUnitID].Location.X, BlueArmy[DisplayUnitID].Location.Y);
Vector2 edge = ArrowEnd - end;
// calculate angle to rotate line
float angle =
(float)Math.Atan2(edge.Y, edge.X);
spriteBatch.Draw(BlueMovementArrow,
new Rectangle(// rectangle defines shape of line and position of start of line
(int)BlueArmy[DisplayUnitID].Location.X + LeftMapOffset,
(int)BlueArmy[DisplayUnitID].Location.Y + TopMapOffset ,
(int)edge.Length(), //sb will strech the texture to fill this rectangle
PieceWidth), //width of line, change this to make thicker line
null,
Color.White * 0.5f, // opacity is 50%,
angle, //angle of line (calulated above)
new Vector2( 0, 0 ), // point in line about which to rotate
SpriteEffects.None,
0);
Whatever values I put into the Vector2 that controls rotation produces very weird results.
Anybody deal with rotating a rectangle that’s generated programmatically (not a sprite)?
Thanks.