0
votes

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.

2
...move very bad. They move like jumping. Can you be more specific? - Charlie Salts
Yes, it doesn't move smoothly. - VansFannel
50ms should be sufficient for smoothness - does your hardware actually supports timers with intervals that low? Have you tried the same code on a normal PC? - Charlie Salts
I'm trying it on the emulator. I think that the error it is here: I'm updating Top adding 5 pixels every Tick. Maybe if I do Panel.Top +=1; is going to work. - VansFannel
@Charlie: All Windows CE devices support timers down to 1ms resolution. - ctacke

2 Answers

2
votes

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!

0
votes

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.