efficient painting and animations with many objects

C

Carsten Marx

Hello,
i need a solution for painting, scaling and animating many objects paralell.
I've tried a few things, especially this:
public void offScreenPainting()
{


Graphics gxOn = this.CreateGraphics();
gxOn.FillRectangle(new SolidBrush(Color.White),r1);
gxOn.FillRectangle(new SolidBrush(Color.White),r2);
gxOn.FillRectangle(new SolidBrush(Color.White),r3);
gxOn.FillRectangle(new SolidBrush(Color.White),r4);
if( i < 200 && bu)
{
i ++;
r1.X +=1; r1.Y += 1;
r2.X += 1;
r3.Y += 1;
r4.X -=1; r4.Y -= 1;
}
else
{
i --;
bu = false;
r1.X -=1; r1.Y -= 1;
r2.X -= 1;
r3.Y -= 1;
r4.X +=1; r4.Y += 1;
if( i < 1) bu = true;
}
gxOn.DrawString("flying Text",f,b,r1);
gxOn.DrawString("flying Text",f,b,r2);
gxOn.DrawString("flying Text",f,b,r3);
gxOn.DrawString("flying Text",f,b,r4);
gxOn.Dispose();

}

My problem is, that if i have a timer for animating things (like a
flying and scaling text on the screen) the screen is flashing....
is there a more efficient way to do this withuot flickering...

And what about the AnimateCtl in OpenNETCF - Library? Could this be
useful for me?

Regards
Carsten
 
C

Chris Tacke, eMVP

Two things I'd look at optimising.

1. Don't do a CreateCraphics with every call to Paint. The Graphics object
won't change through the life of the control, so get it once and reuse it to
minimize creation overhead.
2. You don't show exactly what's going on to get this stuff to the screen,
but my guess is you're drawing right to it, which is bad. It will be slow
and flicker terribly. Create a bitmap the size of your control (again, only
once and reuse it). Do all drawing to that Bitmap, then at the very end use
DrawImage to paint it into the control's on-screen Graphics object. THe
code you posted isn't doing much and it should be very smooth. Once again I
point to the source for the SDF's RoundGauge which uses this technique
extensively.


--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
C

Carsten Marx

Two things I'd look at optimising.

1. Don't do a CreateCraphics with every call to Paint. The Graphics object
won't change through the life of the control, so get it once and reuse it to
minimize creation overhead.
2. You don't show exactly what's going on to get this stuff to the screen,
but my guess is you're drawing right to it, which is bad. It will be slow
and flicker terribly. Create a bitmap the size of your control (again, only
once and reuse it). Do all drawing to that Bitmap, then at the very end use
DrawImage to paint it into the control's on-screen Graphics object. THe
code you posted isn't doing much and it should be very smooth. Once again I
point to the source for the SDF's RoundGauge which uses this technique
extensively.
ok, in a form now it works perfect....
but when i use the same technique in a panel i get a
NotSupportedException... Why this.... ?

Regards

Carsten
 
S

Sergey Bogdanov

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top