我尝试制作像PingPong一样的动画球,它正在工作,但有图形闪烁。我搜索网络没什么帮助我。我有双缓冲表单,我尝试使用绘图与位图,但然后球不会显示。 这是我的球动画代码:
protected PictureBox pictureBox;
protected Graphics graphics;
//
public MoveBall(PictureBox pictureBox)
{
this.pictureBox = pictureBox;
graphics = pictureBox.CreateGraphics();
}
//
public void AnimateBall(List<Point> positions, Ball ball)
{
foreach (Point point in positions)
{
graphics.FillEllipse(new SolidBrush(pictureBox.BackColor), new Rectangle(ball.Position.X - Convert.ToInt32(Convert.ToDouble(ball.Width) * 0.5), ball.Position.Y - Convert.ToInt32(Convert.ToDouble(ball.Height) * 0.5), ball.Width, ball.Height));
ball.Position = point;
graphics.FillEllipse(new SolidBrush(ball.Color), new Rectangle(point.X - Convert.ToInt32(Convert.ToDouble(ball.Width) * 0.5), point.Y - Convert.ToInt32(Convert.ToDouble(ball.Height) * 0.5), ball.Width, ball.Height));
Thread.Sleep(1);
}
}