Drawing, shapes? Canvas? Disk Defrag map style lazarus / 31-LCL ---------------------------------------------------------------------- Tony Stone · 2021-09-25 01:18 So I have an idea to draw a 'progress map' one of my programs.  Think of the old disc derangementer disc representation squares...  See my attached screen shots. So below is my code so far.  Works pretty good EXCEPT... it is VERY slow at creating the squares and distributing them in the scrollbox.  I may end up wanting over 100k squares...  It takes about a minute to make 400 squares on my i7 3.xghz What could I do to make thousands and thousands of squares substantially faster?  I also need to have a hint for each square and need to change color properties as i go....  any other comments about my code would be appreciated as the truth is, i barely know what I am doing.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,  Spin, StdCtrls; type   { TForm1 }   TForm1 = class(TForm)    btnCreate: TButton;    btnDestroy: TButton;    btnRedistribute: TButton;    chkDoRandom: TCheckBox;    ScrollBox1: TScrollBox;    SpinEdit1: TSpinEdit;    tmrRndDarken: TTimer;    tmrReRnd: TTimer;    procedure btnCreateClick(Sender: TObject);    procedure btnDestroyClick(Sender: TObject);    procedure btnRedistributeClick(Sender: TObject);    procedure chkDoRandomChange(Sender: TObject);    procedure Distribute(Sender: TObject);    procedure FormResize(Sender: TObject);    procedure tmrRndDarkenTimer(Sender: TObject);    procedure tmrReRndTimer(Sender: TObject);   private   public    totalsquares: Int64;    rightmost: Integer;     sqCompleteness: array of Integer;    sqReady2Dis: Boolean;    end; aSquare = record        hits: Integer;        RiClr: Integer;        GiClr: Integer;        BiClr: Integer;        square: TShape;end; var  Form1: TForm1;  aSquareArray: Array of aSquare;implementation {$R *.lfm} { TForm1 }   procedure TForm1.btnCreateClick(Sender: TObject);var  i: Int64; begin  totalsquares:=SpinEdit1.Value;  Randomize;  for i:= 0 to totalsquares-1 do begin    SetLength(aSquareArray,i+1);    aSquareArray[i].square:=TShape.Create(ScrollBox1);    aSquareArray[i].square.Parent:=ScrollBox1;    //aSquareArray[i].square.Shape:=stRoundRect;    aSquareArray[i].square.Brush.Color:=clWhite;    aSquareArray[i].RiClr:=0;    aSquareArray[i].GiClr:=0;    aSquareArray[i].BiClr:=0;    aSquareArray[i].square.hint:='Square: #' + IntToStr(i+1);  end;   btnCreate.Enabled:=False;  sqReady2Dis:=True;  Distribute(Self);end; procedure TForm1.btnDestroyClick(Sender: TObject);var  i: Integer;begin  tmrRndDarken.Enabled:=False;  chkDoRandom.Checked:=False;   for i:= 0 to totalsquares-1 do begin    aSquareArray[i].square.Destroy;  end;   SetLength(aSquareArray,0);  btnCreate.Enabled:=true;  sqReady2Dis:=False;end; procedure TForm1.btnRedistributeClick(Sender: TObject);begin  Distribute(self);end;  procedure TForm1.chkDoRandomChange(Sender: TObject);begin  tmrRndDarken.Enabled:=chkDoRandom.Checked;end;   procedure TForm1.Distribute(Sender: TObject);var  i: Integer;  lastleft: integer;  lasttop: Integer;  sqSpacing: integer = 1;  sqWidth: Integer = 10;  sqHeight: Integer = 10;  maxleft: Integer;begin   maxleft:=ScrollBox1.Width - sqWidth - sqSpacing - ScrollBox1.VertScrollBar.Size;  lastleft:=sqSpacing;  lasttop:=sqSpacing;   for i:= 0 to totalsquares-1 do begin    if lastleft > maxleft then begin      lasttop:=lasttop+sqHeight+sqSpacing;      lastleft:=sqSpacing;    end;    aSquareArray[i].square.Top:=lasttop+sqSpacing;    aSquareArray[i].square.Left:=lastleft;    aSquareArray[i].square.Width:=sqWidth;    aSquareArray[i].square.Height:=sqHeight;     lastleft:=sqWidth+aSquareArray[i].square.left+sqSpacing;   end;end; procedure TForm1.FormResize(Sender: TObject);begin  //if sqReady2Dis then Distribute(Self);end; procedure TForm1.tmrRndDarkenTimer(Sender: TObject);var  rndSQR: integer;  myR, myG, myB: Integer;begin   if totalsquares > 2 then begin     rndSQR:=random(totalsquares);    if aSquareArray[rndSQR].GiClr = 0 then begin     aSquareArray[rndSQR].GiClr:=255;    end;     if aSquareArray[rndSQR].GiClr > 1 then dec(aSquareArray[rndSQR].GiClr,1);     aSquareArray[rndSQR].square.Bru sh.Color:=RGBToColor(aSquareArray[rndSQR].RiClr,aSquareArray[rndSQR].G iClr,aSquareArray[rndSQR].BiClr);  end;end; procedure TForm1.tmrReRndTimer(Sender: TObject);begin  Randomize;end;  end. ---------------------------------------------------------------------- m.abudrais · 2021-09-25 02:12 try TImage Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, dateutils; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    Timer1: TTimer;    procedure Button1Click(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    LastTime: TDateTime;    TimeCounter: integer;    procedure UpdateImage;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  TimeCounter := 0;  UpdateImage;end; procedure TForm1.Timer1Timer(Sender: TObject);var  M: int64;begin  UpdateImage;  Inc(TimeCounter);  M := MilliSecondsBetween(LastTime, Now);  if M > 5000 then  begin    Form1.Caption := round(50 * 100 * TimeCounter / (M / 1000)).ToString();    LastTime := Now;  end;end; procedure TForm1.UpdateImage;var  k: integer;  m: integer;  c: TCanvas;  R: int64;begin  c := Image1.Canvas;  c.Brush.Color := clBlack;  c.FillRect(0, 0, Image1.Width, Image1.Height);  c.Brush.Color := clBlue;  for k := 0 to 50 do  begin    for m := 0 to 100 do    begin    R := Random(10);      if R > 5 then        c.Brush.Color := clBlue      else        c.Brush.Color := clGreen;      c.FillRect(m * 10, k * 10, m * 10 + 8, k * 10 + 8);    end;  end;end; end. if you need more performance you can use other lib like https://wiki.freepascal.org/BGRABitmap ---------------------------------------------------------------------- Handoko · 2021-09-25 02:31 TCanvas is slow, and TShape uses TCanvas. Using arrays of TShape to draw thousands of shapes is both slow and not memory-wise. Here has a simple demo showing how to draw thousands of objects using buffer for (slightly) improving the performance (try moving2): https://forum.lazarus.freepascal.org/index.php/topic,38136.msg263143.h tml#msg263143 TDrawGrid as suggested by jamie or using a TImage is better than using array of TShapes. But if you need better performance, you should consider to use hardware accelerated graphics libraries like Allegro.pas, TOpenGLControl, SDL. https://wiki.freepascal.org/Game_framework If learning a hardware-accelerated graphics library is too difficult, you may try Graphics32. I heard it is not hardware-accelerated but still very fast. https://en.wikipedia.org/wiki/Graphics32 ---------------------------------------------------------------------- Tony Stone · 2021-09-25 02:33 So this is cool.  I copied it into a new project.  It looks like it performs quite well.  However, I would like to be able to display a Hint for each square.  Each squares is gonna represent some information so in a way I need to have some information stored with each square... which might be possible to associate the square coordinates with a mouse over event and trigger a hint.  Just seems like a lot of work.  I feel like there is something easy I am overlooking? Thanks for your demo either way.  It is a start for sure!  And it only took you about 15 minutes to put that together?  Mine took me several hours.    Quote from: m.abudrais on September 25, 2021, 04:12:21 amtry TImage Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, dateutils; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Image1: TImage;    Timer1: TTimer;    procedure Button1Click(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    LastTime: TDateTime;    TimeCounter: integer;    procedure UpdateImage;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin  TimeCounter := 0;  UpdateImage;end; procedure TForm1.Timer1Timer(Sender: TObject);var  M: int64;begin  UpdateImage;  Inc(TimeCounter);  M := MilliSecondsBetween(LastTime, Now);  if M > 5000 then  begin    Form1.Caption := round(50 * 100 * TimeCounter / (M / 1000)).ToString();    LastTime := Now;  end;end; procedure TForm1.UpdateImage;var  k: integer;  m: integer;  c: TCanvas;  R: int64;begin  c := Image1.Canvas;  c.Brush.Color := clBlack;  c.FillRect(0, 0, Image1.Width, Image1.Height);  c.Brush.Color := clBlue;  for k := 0 to 50 do  begin    for m := 0 to 100 do    begin    R := Random(10);      if R > 5 then        c.Brush.Color := clBlue      else        c.Brush.Color := clGreen;      c.FillRect(m * 10, k * 10, m * 10 + 8, k * 10 + 8);    end;  end;end; end. if you need more performance you use other lib like https://wiki.freepascal.org/BGRABitmap ---------------------------------------------------------------------- Tony Stone · 2021-09-25 03:07 Quote from: jamie on September 25, 2021, 04:08:21 amThat isn't going to spawn much fruit..  You should not be creating a GUI control for each square, you will hit a way and things will just stop! Also, the scrollbox has a limit on the scrolling range and client size limits will change depending on the screen size.  You should look at the TDrawGrid and implement drawing your own square areas... Yeah... spawned square fruit... slowly. lol It did kind of "work" at least.   I am looking at drawgrid now.  I think I looked at it initially and stopped focusing on it as i believe its the control that looked like a spreadsheet type control... ---------------------------------------------------------------------- Tony Stone · 2021-09-25 03:11 Quote from: jamie on September 25, 2021, 04:08:21 amThat isn't going to spawn much fruit..  You should not be creating a GUI control for each square, you will hit a way and things will just stop! Also, the scrollbox has a limit on the scrolling range and client size limits will change depending on the screen size.  You should look at the TDrawGrid and implement drawing your own square areas... So drawgrid may be the solution.  I will have to revisit the progressbar in a cell of a tstringgrid that you helped me with a few weeks ago... hmmm.... ---------------------------------------------------------------------- loaded · 2021-09-25 07:42 Actually, the fastest drawing method is OpenGL, but if you are going to make queries and similar operations other than drawing, you will find a lot of problems on your lap. Another alternative is to use Image object and Thread, there seems to be no problem this duo can't handle. Of course for me You can use the mathematical order you created for the squares during the query. It doesn't matter if you have thousands of frames. Thus, you can easily understand which frame the mouse is on the screen. CAD software also works on this logic. ---------------------------------------------------------------------- wp · 2021-09-25 08:39 Your initial solution using the TShape controls is probably slow only because the ScrollBox recalculates its size and repaints itself whenver you add or move each Shape. I cannot check it (you should always add a compilable project rather than pasting a code snippet which is useless for somebody who wants to test your code), but I guess that temporarily turning off AutoScroll could prevent that. For the DrawGrid solution you were asking about how to show a hint for each cell. Turn on the grid's ShowHint, activate the option goCellHints and write a handler for OnGetCellHint to provide the hint text for the particular cell specified by the row/column index parameters. ---------------------------------------------------------------------- Tony Stone · 2021-09-25 13:42 Quote from: wp on September 25, 2021, 10:39:34 amYour initial solution using the TShape controls is probably slow only because the ScrollBox recalculates its size and repaints itself whenver you add or move each Shape. I cannot check it (you should always add a compilable project rather than pasting a code snippet which is useless for somebody who wants to test your code), but I guess that temporarily turning off AutoScroll could prevent that. For the DrawGrid solution you were asking about how to show a hint for each cell. Turn on the grid's ShowHint, activate the option goCellHints and write a handler for OnGetCellHint to provide the hint text for the particular cell specified by the row/column index parameters. I actually was going to add a compilable project however I am running the trunk version of Lazarus... And for whatever reason it seems no one can ever open my projects unless they are on trunk version as well.  Some thing I have been meaning to look into and report a bug if needed... ---------------------------------------------------------------------- Tony Stone · 2021-09-25 14:21 Quote from: loaded on September 25, 2021, 09:42:04 amActually, the fastest drawing method is OpenGL, but if you are going to make queries and similar operations other than drawing, you will find a lot of problems on your lap. Another alternative is to use Image object and Thread, there seems to be no problem this duo can't handle. Of course for me You can use the mathematical order you created for the squares during the query. It doesn't matter if you have thousands of frames. Thus, you can easily understand which frame the mouse is on the screen. CAD software also works on this logic. I was thinking last night this may be cool to handle with an additional thread.  I just couldn't exactly figure out in my head the best way to get started with it being as the thread can't handle GUI stuff directly.  I think maybe my first step will be to figure out how to do my drawing with the timage.  Then I will certainly be back with relevant questions So tonight when I get time to play I am gonna try a drawgrid implementation and start the timage....  See you all soon.  Unless of course someone comes up with an even better way not discussed yet. .  And I don't think I'm ready to tackle OpenGL... In a few years I'll try. ---------------------------------------------------------------------- Seenkao · 2021-09-25 16:50 На самом деле OpenGL или DirectX (Windows) будет лучшим решением для данного решения. Но Bitmap тоже можно использовать, но вы должны уметь им достаточно быстро выводить квадратики. В данном случае лучше всего нарисовать изображение квадратика и спрайтом выводить его, в том количестве, в каком это необходимо. Используя буфер. И в конечном итоге выводить этот буфер на экран. Это будет работать достаточно быстро! Yandex translate: In fact, OpenGL or DirectX (Windows) will be the best solution for this solution. But Bitmap can also be used, but you should be able to output squares with it quickly enough. In this case, it is best to draw an image of a square and output it with a sprite, in the amount in which it is necessary. To do this, use the buffer. And eventually output this buffer to the screen. This will work fast enough! An example of a program where I made a game. Note this code at the end:   Buf.Canvas.Draw(Tank[1].x, Tank[1].y, Tanki[1, Tank[1].Povorot, Tank[1].Anim]);   Form1. Canvas. Draw(0, 0, Buf); this is the basis for displaying all sprites on the screen (i apologize for the comments in Russian... I just copied the code). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; interface uses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, ExtCtrls; type  TForm1 = class(TForm)    Timer1: TTimer;    procedure FormCreate(Sender: TObject);    procedure Timer1Timer(Sender: TObject);    procedure FormKeyDown(Sender: TObject; var Key: Word;      Shift: TShiftState);    procedure FormKeyUp(Sender: TObject; var Key: Word;      Shift: TShiftState);  private    { Private declarations }  public    { Public declarations }  end; type  TTank = record    Speed, x, y, Povorot, Anim: Integer;      // скорость, координаты, направление    Go, Fight, Vistrel, Visible: Boolean;  // движемся или стоим?, стрельба, выстрелили ли мы уже?, видим или нет    Zaderhka_Visrela, Max_Vistrel: Integer;  // таймер задержки выстрела, и сама задержка    poyehal: Boolean;  end; type  TPulya = record    x, y, Speed, Povorot: Integer;      // координаты, скорость, направление    visible: Boolean;                 // видна ли пуля?  end; type  TFlag = record    x, y: integer;    Pic: TBitmap;  end; var  Form1: TForm1;  Tanki: array[1..2, 1..4, 1..4] of TBitmap;  // 1-2 - два вида танков, 1-4 - направление                                              // 1-2 движение гусениц фнимация и 3-4 - анимация с выстрелом   Textures: array[1..3, 1..3] of TBitmap;     // Массив картинок карты (земля, вода, лес)(.. .. последнее зима)  Flag: array[1..2] of TFlag;         // написано что характеристики и картинки флагов соперников на карте????  Map: array[0..10, 0..10] of Integer;  // Массив клеток игровой карты  Tank: array[1..4] of TTank;  Puli: array[1..20] of TPulya;  Pulya: array[1..4] of TBitmap;  Buf: TBitmap;        //Рисунок пули и буфер  path: string;               // будет хранить путь к игре  qUp, qDown, qLeft, qRight: Boolean;  i, j, k: Integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject);var  i, j: Integer;begin  path := ExtractFileDir(Application.ExeName);  //загрузка картинок танков  for i := 1 to 4 do    for j := 1 to 4 do    begin      Tanki[1, j, i] := TBitmap.Create;                 // загружаем картинки для первого танка (нашего, основного)      Tanki[1, j, i].TransparentColor := clWhite;      Tanki[1, j, i].Transparent := True;      Tanki[1, j, i].LoadFromFile(path + '\img\' + 'т1' + IntToStr(j) + IntToStr(i) + '.bmp');      Tanki[2, j, i] := TBitmap.Create;                 // загружаем картинки для второго танка (противник)      Tanki[2, j, i].TransparentColor := clWhite;       // картинки надо переделать    Tanki[2, j, i].Transparent := True;      Tanki[2, j, i].LoadFromFile(path + '\img\' + 'т2' + IntToStr(j) + IntToStr(i) + '.bmp');    end;  //загружаем текстуры  for i := 1 to 3 do  begin    Textures[1, i] := TBitmap.Create;                                            // земля - полностью проходима    Textures[1, i].LoadFromFile(path + '\img\' + 'земля' + IntToStr(i) + '.bmp');    Textures[2, i] := TBitmap.Create;                                            // вода - проходима только зимой (один раз, лёд ломается)    Textures[2, i].LoadFromFile(path + '\img\' + 'вода' + IntToStr(i) + '.bmp');    Textures[3, i] := TBitmap.Create;                                            // лес - проходим, но скрывает танк,//    Textures[3, i].TransparentColor := Textures[3, i]    Textures[3, i].LoadFromFile(path + '\img\' + 'лес' + IntToStr(i) + '.bmp');    // надо установить прозрачность  end; //загружаем рисунок пули в массив  for i := 1 to 4 do  begin    Pulya[i] := TBitmap.Create;    Pulya[i].TransparentColor := clWhite;    Pulya[i].Transparent := True;    Pulya[i].LoadFromFile(path + '\img\' + 'снаряд' + IntToStr(i) + '.bmp');  end;   Buf := TBitmap.Create; // буфер для визуальной карты  Buf.Width := 600;  Buf.Height := 600;   qLeft := False; //объект стоит и сообщаем что все кнопки отжаты  qUp := False;  qDown := False;  qRight := False;   Tank[1].Speed := 10;  Tank[1].x := 60;  Tank[1].y := 540;  Tank[1].Povorot := 1;  Tank[1].Go := False;  Tank[1].Anim := 1;  Tank[1].Fight := False;  Tank[1].Zaderhka_Visrela := 0;  Tank[1].Max_Vistrel := 10;  Tank[1].Vistrel := False;  Tank[1].Visible := True;   Tank[2].Speed := 7;  Tank[2].x := 480;  Tank[2].y := 0;  Tank[2].Povorot := 3;  Tank[2].Go := False;  Tank[2].Anim := 1;  Tank[2].Fight := False;  Tank[2].Zaderhka_Visrela := 0;  Tank[2].Max_Vistrel := 10;  Tank[2].Vistrel := False;  Tank[2].poyehal := False;  Tank[2].Visible := True;   Tank[3].Speed := 5;  Tank[3].x := 540;  Tank[3].y := 60;  Tank[3].Povorot := 3;  Tank[3].Go := False;  Tank[3].Anim := 1;  Tank[3].Fight := False;  Tank[3].Zaderhka_Visrela := 0;  Tank[3].Max_Vistrel := 5;  Tank[3].Vistrel := False;  Tank[3].poyehal := False;  Tank[3].Visible := True;   for i := 1 to 20 do  begin    Puli[i].x := 0;    Puli[i].y := 0;    Puli[i].Speed := 20;    Puli[i].Povorot := 0;    Puli[i].visible := False;  end;   Flag[1].x := 9;  Flag[1].y := 0;  Flag[2].x := 0;  Flag[2].y := 9;  Flag[1].Pic := TBitmap.Create;//  Flag[1].Pic.TransparentColor := clWhite;  Flag[1].Pic.Transparent := True;  Flag[2].Pic := TBitmap.Create;  Flag[2].Pic.Transparent := True;  Flag[1].Pic.LoadFromFile(path + '\img\флаг1.bmp');  Flag[2].Pic.LoadFromFile(path + '\img\флаг2.bmp');     //случайное генерирование карты  Randomize;  k := Random(3) + 1;   //выбираем один из 3-х факторов, вроде зима, лето, осень...  for i := 0 to 9 do    for j:= 0 to 9 do    begin      Map[i, j] := Random(100) + 1;      if Map[i, j] <= 50 then Map[i, j] := 1;      if (Map[i, j] > 50) and (Map[i, j] <= 80) then Map[i, j] := 3;      if Map[i, j] > 80 then Map[i, j] := 2;    end;    Map[Trunc(Tank[1].x / 60), Trunc(Tank[1].y / 60)] := 1;end; procedure TForm1.Timer1Timer(Sender: TObject);var  i, j: Integer;begin// рисуем карту и танк на ней  for i := 0 to 9 do    for j := 0 to 9 do      Buf.Canvas.Draw(i * 60, j * 60, Textures[Map[i, j], k]);   if Tank[1].Go = True then  begin    if Tank[1].Anim = 1 then Tank[1].Anim := 2    else Tank[1].Anim := 1;   // UP    if (Tank[1].Povorot = 1) and (Map[Trunc(Tank[1].x / 60), Trunc((Tank[1].y - Tank[1].Speed) / 60)] = 1)        and (Map[Trunc((Tank[1].x + 59) / 60), Trunc((Tank[1].y - Tank[1].Speed) / 60)] = 1)        and (Tank[1].y - Tank[1].Speed >= 0) then Tank[1].y := Tank[1].y - Tank[1].Speed;    // расписываю. Если движение наверх и при этом выше левого угла танка нет препятствия и выше правого угла  // нет препятствия и при этом не находимся на самом верху карты, то продолжаем двигаться наверх.     //DOWN    if (Tank[1].Povorot = 3) and (Map[Trunc(Tank[1].x / 60), Trunc((Tank[1].y + Tank[1].Speed + 59) / 60)] = 1)        and (Map[Trunc((Tank[1].x + 59 )/ 60), Trunc((Tank[1].y + Tank[1].Speed + 59)/60)] = 1)        and (Tank[1].y + Tank[1].Speed <= 540) then Tank[1].y := Tank[1].y + Tank[1].Speed;     //RIGHT    if (Tank[1].Povorot = 2) and (Map[Trunc((Tank[1].x + Tank[1].Speed + 59) / 60), Trunc(Tank[1].y / 60)] = 1)        and (Map[Trunc((Tank[1].x + Tank[1].Speed + 59) / 60), Trunc((Tank[1].y + 59) / 60)] = 1)        and (Tank[1].x + Tank[1].Speed <= 540) then Tank[1].x := Tank[1].x + Tank[1].Speed;     //LEFT    if (Tank[1].Povorot = 4) then      if (Map[Trunc((Tank[1].x - Tank[1].Speed) / 60), Trunc(Tank[1].y / 60)] = 1)        and (Map[Trunc((Tank[1].x - Tank[1].Speed) / 60), Trunc((Tank[1].y + 59) / 60)] = 1)        and (Tank[1].x - Tank[1].Speed >= 0) then     //   begin          Tank[1].x := Tank[1].x - Tank[1].Speed;      //    Tank[1].      //  end;  end;  Buf.Canvas.Draw(Tank[1].x, Tank[1].y, Tanki[1, Tank[1].Povorot, Tank[1].Anim]);  Form1.Canvas.Draw(0, 0, Buf);end; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  if Key = 87 then  begin    qUp := True;    Tank[1].Go := True;    Tank[1].Povorot := 1;  end;  if Key = 65 then  begin    qLeft := True;    Tank[1].Go := True;    Tank[1].Povorot := 4;  end;  if Key = 83 then  begin    qDown := True;    Tank[1].Go := True;    Tank[1].Povorot := 3;  end;  if Key = 68 then  begin    qRight := True;    Tank[1].Go := True;    Tank[1].Povorot := 2;  end;end; procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  if (Key = 87) then qUp := False;  if Key = 65 then qLeft := False;  if Key = 83 then qDown := False;  if Key = 68 then qRight := False;  if (qUp = False) and (qLeft = False) and (qRight = False) and (qDown = False) then Tank[1].Go := False;end; end. ---------------------------------------------------------------------- wp · 2021-09-25 17:34 Quote from: Tony Stone on September 25, 2021, 03:42:10 pmI actually was going to add a compilable project however I am running the trunk version of Lazarus... And for whatever reason it seems no one can ever open my projects unless they are on trunk version as well.  Some thing I have been meaning to look into and report a bug if needed... Go to Project Options > Miscellaneous and check the box "Maximize compatibility of project files (LPI and LPS)" - this way the old file format will be written and users of Laz 2.0.x or older still can open the project. Users not having Lazarus trunk/2.2RC1 can convert a project from the new to the old format by using the utility "FixLP" on CCR (https://sourceforge.net/p/lazarus- ccr/svn/HEAD/tree/applications/fixlp/). ---------------------------------------------------------------------- loaded · 2021-09-25 18:28 Quote from: Tony Stone on September 25, 2021, 04:21:43 pmI was thinking last night this may be cool to handle with an additional thread.  I just couldn't exactly figure out in my head the best way to get started with it being as the thread can't handle GUI stuff directly.  I think maybe my first step will be to figure out how to do my drawing with the timage.  Then I will certainly be back with relevant questions So tonight when I get time to play I am gonna try a drawgrid implementation and start the timage....  See you all soon.  Unless of course someone comes up with an even better way not discussed yet. .  And I don't think I'm ready to tackle OpenGL... In a few years I'll try. Threads cannot access the user graphics unit directly. This is true. But the trick is, you do the drawing process to an object of tbitmap type (we call it buffering) in the thread, you transfer the timage object over the main thread with the synchronized method at an interval you specify while the drawing process continues, you complete the drawing without any disturbing situation for the user. I say it again. This is how CAD applications work. Thus, they overcome scenarios of drawing and interrogating thousands of shape objects on the screen. If you are dealing with graphic works and if you are going to deal with it in the future, it is very useful to learn this method. ---------------------------------------------------------------------- paweld · 2021-09-25 19:39 DrawGrid? ---------------------------------------------------------------------- Joanna · 2021-09-26 01:08 It shouldn’t be too difficult to make hints for each of the squares using logic inside of the onshowhint event. It all depends upon the criterion of how each hint relates to each square.