Game Development - Flicker-Free

I am developing a tetris type game in winforms (C # and .netframework 2.0). Winform has a background image and a drawer that moves down (a new location is assigned) at 500 ms intervals.

The problem is that the picture moves down the background image of the flicker form at the point where the box with the image was previously located. If I do not use the background image, then it does not flicker.

Is there any kind of graphics accelerator or any solution that can be used to solve the flicker problem?

+4
source share
3 answers

The term Double Buffering used for this. The idea is simple - start with 2 panels, but just display them. Draw a hidden panel and quickly change the hidden and visible panels. Rinse and repeat for each transition (animation).

Fortunately, you don't have to deal with the nuts and bolts of this in .NET, the controls do it for you. This SO question will help you: How to duplicate .NET controls on a form?

+3
source

Set DoubleBuffered = true to the controls. This should help prevent flickering.

For documentation on the DoubleBuffered property, see here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.doublebuffered.aspx

+3
source

If you are developing a game in Windows Forms, you really need to override OnPaint and implement sprite painting on every frame, as opposed to moving the PictureBox controls in heavy weight.

You will find that you can get flicker regardless of DoubleBuffer if you use the approach you mentioned. However, using the entire drawing made in OnPaint, DoubleBuffer starts to work.

I did a quick search and found this interesting article about creating a game loop in Windows Forms using the OnPaint override. In particular, take a look at GameStateDrawer , which does rendering directly in the graphics context.

+3
source

Source: https://habr.com/ru/post/1414095/


All Articles