s00014405

s00014405

  • NA
  • 24
  • 0

Painting on an image leaves trail?

Nov 17 2004 2:50 PM
I've been developing an Air Hockey project and i only started using GDI+ I know people told me on here that GDI+ would not be fast enough for this Air Hockey game (and to use C# instead) but i think an element of the project for me will be to test the limits of GDI+. Anyways, i'm a real beginner at GDI+ and i've been looking at a couple of examples and am reading up on it. Back to the point - i'm drawing a puck and paddle on a PictureBox control of a table. And manipulating them according to the mouse movements. Am just working on the paddle right now but am getting a trail when i move the paddle around. How do i clear this trail? I tried using the g.Clear(Color.Transparent) etc. but it's clearing the PictureBox completely. Would i need to use the Invalidate method to do this? This is what i mean by a trail.. http://homepage.eircom.net/~basquilletj/GdiPlusTrail.JPG Any suggestions would be much appreciated! Sample of some of my code below: Thanks in advance! private void frmTable_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { { g = Graphics.FromImage(picTable.Image); gameDraw(); } private void gameDraw() { // all brushes SolidBrush redBrush = new SolidBrush(Color.FromArgb(255,50,50)); Pen blackPen = new Pen( Color.Black, 2 ); Pen bluePen = new Pen( Color.Blue, 2 ); //draw puck g.FillEllipse( redBrush, puck_x, puck_y, 32, 32 ); g.DrawEllipse( blackPen, puck_x, puck_y, 32, 32 ); //draw paddle g.FillEllipse( redBrush, paddle_x, paddle_y, 32, 32 ); g.DrawEllipse( bluePen, paddle_x, paddle_y, 32, 32 ); bluePen.Dispose(); redBrush.Dispose(); blackPen.Dispose(); } private void gameLoop(Object sender, EventArgs e) { if ( paddle_x <= 0 ) x_vel *= -1; if ( paddle_y <= 0 ) y_vel *= -1; //Called so the form will repaint itself. Invalidate(); } private void frmTable_Load(object sender, System.EventArgs e) { gameClock = new Timer(); //Start the game clock to control game speed gameClock.Interval = 15; gameClock.Tick += new EventHandler(gameLoop); gameClock.Start(); // initial dimensions for puck puck_x = 200; puck_y = 200; // initial dimensions for paddle paddle_x = 150; paddle_y = 150; } private void picTable_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { paddle_x = e.X-10; paddle_y = e.Y-10; }

Answers (10)