K
K
Kiril12212020-05-10 18:22:01
C++ / C#
Kiril1221, 2020-05-10 18:22:01

C# How to get rid of flicker?

I have read about 100 articles already, but of course it’s worth complicating it a little, and hello flicker, 4 lines cannot be drawn.
I'm already doing Double Double Tribol buffer, and probably tried 32 combinations. + I also give the form itself doubleBuffer=true and I've mixed all this a million times already, nothing helps.

/// Form1.cs        
     GameManager = new GameManager{
                PaintDilegate = () => this.panelGame.Invalidate(),
                PaintInitDilegate = (PaintEventHandler fun) => { this.Paint += fun; },         
            };
       GameManager .init();
       }
   ///////////////////////////
 ///////// GameManager.cs
  class    GameManager {
              /////
            Bitmap DoubleBuffer;
            Graphics gBuf;
           public init(){
                     this.PaintInitDilegate?.Invoke( Paint );          
           }
public void Paint(object sender,PaintEventArgs e)
{
          e.Graphics.DrawImage(DoubleBuffer,0,0);
}
/// вызывается в таймере  постоянно
          public void update(object srnder,PaintEventArgs e){
              if(DoubleBuff==null || (DoubleBuf.Width!=Width){
                       DoubleBuf?.Disponse();
                        DoubleBuffer = new Bitmap(Width, Height);
                         gBuf = Graphics.FromImage(DoubleBuffer); 
                          initMap();     //  ...  нарисовать карту         
              }
              Game.Map.ForEach( (x,y,brushIndex)=>{
                       ///..................  
                       gBuf.FillRect(  ....);
             }
             PaintDilegate?.Invoke(); // отослать панели команду перерисовать
          }
   }

Here's something like this code, if I rewrote it correctly, everything works, there are no leaks or something like that,
But I can't get rid of Blinks.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question