So i wanted to rotate my sprite so that it was always looking at the mouse position. I am using the following code:
public void draw(SpriteBatch sb)
{
int mouse_x = Mouse.GetState().X;
int mouse_y = Mouse.GetState().Y;
float angles = Calc.getAngle(new Vector2(mouse_x, mouse_y));
sb.Draw(texture, position, null, Color.White, angles, origins, SpriteEffects.None, 1);
}
//Calc.cs method
public static float getAngle(this Vector2 v)
{
return (float)Math.Atan2(v.Y, v.X);
}
I am getting the following error:
Argument 2: cannot convert from ‘Microsoft.Xna.Framework.Vector2’ to ‘Microsoft.Xna.Framework.Rectangle’
I thought I had the parameters correct, but obviously not. I can’t figure out why it won’t accept a vector for the position.
Any help please?
According to MSDN the method with 8 parameters takes a Rectangle, not a Vector2. There are some methods with 9 parameters and a Vector2. Are you missing a parameter?