Drawing from XML parsing

164 views Asked by At

I am trying to draw a moving circle based on coordinates read from an XML file. At the moment the circle will only draw once. Could someone show me where I'm going wrong?!

The EyeMove method is called within a loop which reads the X and Y strings from the XML and parses to float

public void EyeMove(float x, float y)
{

    point = new PointF(x, y);
    Invalidate();


}

protected override void OnPaint(PaintEventArgs e)
{
    base.OnPaint(e);
    DrawCircle(e.Graphics, point.X, point.Y);
}

private void DrawCircle(Graphics g, float x, float y)
{

    using (Brush semiTransBrush = new SolidBrush(Color.Coral))
    {
        using (Pen pen = new Pen(Color.Aquamarine, 2))
        {
            g.DrawEllipse(pen, x, y, 50, 50);
            g.FillEllipse(semiTransBrush, x, y, 50, 50);

        }
    }
}
1

There are 1 answers

0
kennyzx On

The loop is executing too fast, the circles are drawn and erased too fast for human eyes to perceive, so what you saw is the last drawn circle. Try to add a delay (~50ms) to each iteration of the loop to slow it down.

The value of the delay is chosen to achieve a suitable FPS for the animation. This page provides some information on the frame rate and human vision.