基本上,我想在鼠标移动的地方画一条线,就像在油漆中一样,但是,当我在 mousePos 上画一个点时,会发生这种情况:
现在,我需要一些帮助把它变成一条线,没有间隙或任何奇怪的东西。感谢您的帮助。
我用来生成线条的代码(这不是图片中的代码!)
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
Line newLine = new Line(pixel, point1, point2, 2, Color.White);
allLines.Add(newLine);
foreach (Line lines in allLines)
{
lines.Draw(spriteBatch);
}
spriteBatch.End();
base.Draw(gameTime);
}
和线对象:
public class Line
{
Texture2D texture;
Vector2 point1, point2;
float width;
Color color;
float angle, length;
public Line(Texture2D texture, Vector2 point1, Vector2 point2, float width, Color color)
{
this.texture = texture;
this.point1 = point1;
this.point2 = point2;
this.width = width;
this.color = color;
angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
length = Vector2.Distance(point1, point2);
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, point1, null, color, angle, Vector2.Zero, new Vector2(length, width), SpriteEffects.None, 0);
}
}