views:

229

answers:

2

Here is screen shot of my game. On the left is my problem, seem "old draw" still existing. On the right is what it should be.

http://img682.imageshack.us/img682/1058/38995989.jpg

drawing code

        Graphics g = e.Graphics;

        for (int i = 1; i < 27; i += 1)
        {
            for (int j = 0; j < 18; j += 1)
            {
                ZPoint zp = zpoints[i, j];

                if (zp != null)
                {
                    g.DrawImage(zp.sprite_index, new Point(zp.x, zp.y));

                    Image arrow;
                    if (zp.sprite_index == spr_green_zpoint)
                    {
                        arrow = spr_green_arrows[zp.image_index];
                    }
                    else if (zp.sprite_index == spr_red_zpoint)
                    {
                        arrow = spr_red_arrows[zp.image_index];
                    }
                    else
                    {
                        arrow = spr_grey_arrows[zp.image_index];
                    }

                    g.DrawImage(arrow, new Point(zp.x - 4, zp.y - 4));
                }
            }
        }

        if (latest_p1 != -1 && latest_p2 != -1)
        {
            ZPoint zp = zpoints[latest_p1, latest_p2];

            if (zp != null)
            {
                g.DrawImage(spr_focus, new Point(zp.x - 6, zp.y - 6));
            }
        }
+1  A: 

There are several methods on the Control class that deal with redrawing:

  • Invalidate - This method marks a particular region of the control as invalid, and will redraw it on the next drawing operation
  • Update - This method triggers a redraw of any invalidated regions
  • Refresh - This method invalidates a control's entire surface and immediately redraws it. Equivalent to calling Invalidate() and Update() in immediate succession.
Adam Robinson
A: 

If your game is never yielding time to the operating system it may not draw things very well. That's where the work of drawing is done. If you insert an Invalidate() call and a "Thread.Sleep(0);" into your code where you want it to refresh the screen it may help.

Jay