我的目标是创建一个灵活的进度条,用于简单的游戏。我正在绘制一条曲线( spline ),然后将这些点提取到一个列表中。然后我有一个选择:我可以使用最后一个点来绘制玩家的位置 - 或者将所有点连接到标记。绘制曲线成功。提取点成功。绘制点是成功的。但是,只要我在表单中添加一个按钮,就会出现一条不需要的线,它将曲线的末端连接到它的起点。问题:如何防止这条不需要的线路?抱歉,我想添加一张图片,但我不明白该怎么做。这是我的代码:-
private void Form1_Paint(object sender, PaintEventArgs e)
{
Point point = new Point(ovalPictMansion.Left - 30, ovalPictMansion.Top - 20);
Size size = new Size(ovalPictMansion.Width + 60, ovalPictMansion.Height + 50);
Rectangle rect = new Rectangle(point, size);
Pen pen = new Pen(Color.DarkKhaki, 9);
e.Graphics.DrawArc(pen, rect, 10, 160);
DrawPath1(e.Graphics, point, pen);
}
GraphicsPath myPath = new GraphicsPath();
private void DrawPath1(Graphics g, Point p, Pen pen)
{
Point[] points1 =
{
new Point(p.X + 10, p.Y + 120),
new Point(p.X - 250, p.Y + 180),
new Point(p.X - 380, p.Y + 390),
new Point(p.X - 430, p.Y + 560),
new Point(p.X - 520, p.Y + 700)
};
g.DrawCurve(pen, points1);
myPath.AddCurve(points1);
g.DrawPath(Pens.Red, myPath);
using (var mx = new Matrix(1, 0, 0, 1, 0, 0))
{
myPath.Flatten(mx, 0.1f);
}
// store points in a list
var list_of_points = new List<PointF>(myPath.PathPoints);
//// Show position of points
//foreach(PointF postnF in list_of_points)
//{
// Point postn = new Point((int)postnF.X - 3, (int)postnF.Y - 3);
// Size size = new Size(6, 6);
// Rectangle rect = new Rectangle(postn, size);
// g.DrawEllipse(Pens.Red, rect);
//}
// Show position of last point only ( track the player )
// Note : The start of the spline is the end of the Player's Path
// So, show the first point ( instead of the last point )
PointF postnF = list_of_points[0];
Point postn = new Point((int)postnF.X - 3, (int)postnF.Y - 3);
Size size = new Size(6, 6);
Rectangle rect = new Rectangle(postn, size);
g.DrawEllipse(Pens.Red, rect);
}