Paintbox+Timer+DoubleBuffered = scintillement !?

Résolu
JulioDelphi Messages postés 2226 Date d'inscription dimanche 5 octobre 2003 Statut Membre Dernière intervention 18 novembre 2010 - 15 mai 2009 à 09:35
JulioDelphi Messages postés 2226 Date d'inscription dimanche 5 octobre 2003 Statut Membre Dernière intervention 18 novembre 2010 - 15 mai 2009 à 14:11
Hello
Comme le dit le titre :
J'utilise une TPaintbox dans laquelle je peins une image de fond, une grille, des pions.
Le timer est réglé sur 45ms ou testé avec 90ms.
DoubleBuffered:= True;
Pourtant j'ai un bien moche scintillement :/
Il y a 144 cases à rafraichir sur lesquelles je dessine mon rectangle + le pion si il existe sur cette case.
Un bout de code :

 with PaintBox1.Canvas do
 begin
   Draw(0,0,bmpFond);
   Pen.Style:= psSolid;
   pen.Color:= clBlack;
   pen.Mode:= pmCopy;
   pen.Width:= 1;
   Brush.Style:= bsClear;
   for X:=1 to 12 do
   for Y:=1 to 12 do
   begin
     Rectangle(0,0,x*55,y*55);
     if Cases[X, Y].NumPiece>0 then
       paintbox1.Canvas.Draw((x-1)*55,(y-1)*55, MonImage);
   end;
 end;

Pourquoi je scintille !

2 réponses

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
15 mai 2009 à 12:41
tu as bien ceci ?

type
  TPiece = record
    // ?
  end;

const
  XCount = 12;
  YCount = 12;
  WCase  = 55;
  HCase  = 55;
  WPic   = WCase * XCount + 1;
  HPic   = HCase * YCount + 1;

var
  Cases   : array[0..XCount-1, 0..YCount-1] of TPiece;
  Rects   : array[0..XCount-1, 0..YCount-1] of TRect;

procedure TFormX.FormXCreate(Sender: TObject);
var X,Y : integer;
begin
  DoubleBuffered := True;
  // If PaintBox1 is in Panel
  // Panel1.DoubleBuffered := True;

  Timer1.Interval := 45; // 25 FPS

  // Precalcul of Rects coordinates
  for X := 0 to XCount-1 do
    for Y := 0 to YCount-1 do
    begin
      Rects[X,Y].Left  := X * WCase;
      Rects[X,Y].Top   := Y * HCase;
      Rects[X,Y].Right := Rects[X,Y].Left + WCase + 1;
      Rects[X,Y].Bottom:= Rects[X,Y].Top  + HCase + 1;
    end;
end;

procedure TFormX.Timer1Timer(Sender: TObject);
begin
  PaintBox1.Refresh;
end;

procedure TFormX.PaintBox1Paint(Sender: TObject);
var X, Y: integer;
begin
 with PaintBox1.Canvas do
 begin
   Draw(0, 0, bmpFond);
  
   //Pen.Style   := psSolid; // default
   //pen.Color   := clBlack; // default
   //pen.Mode    := pmCopy;  // default
   //pen.Width   := 1;       // default
   Brush.Style := bsClear;
  
   for X := 0 to XCount-1 do
     for Y := 0 to YCount-1 do
     begin
       Rectangle(Rects[X,Y]);
       if Cases[X,Y].NumPiece > 0 then
         Draw(Rects[X,Y].Left+1, Rects[X,Y].Top+1, MonImage);
     end;
 end;
end;

<hr size="2" width="100%" />
3
JulioDelphi Messages postés 2226 Date d'inscription dimanche 5 octobre 2003 Statut Membre Dernière intervention 18 novembre 2010 14
15 mai 2009 à 14:11
Merci !
Le problème venait que je repeins tout dans le Timer, alors que je dois repeindre dans le OnPaint et dans le Timer je dois faire un Refresh !
La ça marche :) super
0
Rejoignez-nous