views:

101

answers:

2

Hello!

I'm developing a Windows Mobile 5.0 or above with .Net Compact Framewor 2.0 SP2 and C#.

I'm trying to "animate" five panels changing their locations on a Timer_Tick event but these panels move very bad. They move like jumping.

What I'm doing wrong?

Thank you.

A: 

You're swapping on-screen panels? That's probably going to require a screen ivalidation and repaint, and that's a recipe for disaster. The device might not even have hardware acceleration (and the emulator display driver is really, really bad).

If you want to "animate" on a mobile device, you're going to have to draw to an offscreen buffer and then blit the result to the screen in one shot, and try to keep what you blit as small as possible.

MSDN has a decent article on animation that you might want to look at.

ctacke
I've been trying to do it as you have tell me, using rectangles instead of Panels and drawing to offscreen buffer, but the animation is worse. Now, using Panel.Left +=1 and an interval of 5 miliseconds, it moves smoothly.
VansFannel
+2  A: 

Not sure about the above comment on using rectangles, but we use double buffering. In a nutshell, you create a Bitmap (with a size of what you need, and in your case it would be the size of the panel). Once created, create a Graphics object from the Bitmap. At this point your have now created an offscreen buffer.

Rendering:
For all drawing calls (DrawString, etc) in your OnPaint method, use the graphics object from the Bitmap that you created. At this moment, you are drawing into memory and not the screen.

Once the drawing is done, you copy the offscreen buffer to the screen. To do this, use the DrawImage method of the Graphics object that was passed to the OnPaint method. The parameter to this call is the Bitmap that was created for the offscreen buffer.


Why does this work?
The flickering that you are seeing is called "Tearing". Your eye is catching the actual drawing to the screen. The double buffer limits this by doing all the drawing to memory, and when it's done, it copies it to screen in 1 call.

Hope this helps!

cbuck12000
Are you talking about doing this on a Custom Control that inherits from Panel? I don't know how to draw a System.Windows.Form.Panel object with double buffer over another control.
VansFannel
The above is for a user control, and not a System.Windows.Form.Panel. You won't need a panel. Your new control would need properties to increment the animation from a the Timer event that you have.
cbuck12000