开发者

Emulating animation with panels on .Net Compact Framework

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.


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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜