Hi folks, im making a resourcemanagement game with a 2d map made of tiles. This is the code im currently using to draw the map:
Code:
procedure TForm2.RepaintMap;
var
  i, i2: integer;
  MaxI, MaxI2: integer;
  Image: TPicture;
begin
  ImgMap.Canvas.Brush.Color:=clBlack;
  ImgMap.Canvas.Pen.Color  :=clBlack;
  ImgMap.Canvas.Rectangle(0, 0, ImgMap.Width, ImgMap.Height);
  Image:= TPicture.create;
  MaxI :=MapInfo.Position.X + ImgMap.Width  DIV TileDIM +1;
  MaxI2:=MapInfo.Position.Y + ImgMap.Height DIV TileDIM +1;
  If MaxI  >= MapInfo.Width  Then MaxI :=MapInfo.Width;
  If MaxI2 >= MapInfo.Height Then MaxI2:=MapInfo.Height;
  For I:=MapInfo.Position.x To MaxI -1 Do
    For I2:=MapInfo.Position.Y To MaxI2 -1 Do
      begin
        begin //Landscape.
          Case MapInfo.Tiles[I][I2].Landscape Of
            ltWater:  Image.LoadFromFile(PathWater);
            ltGras:   Image.LoadFromFile(PathGras);
            ltSand:   Image.LoadFromFile(PathSand);
            ltForest: Image.LoadFromFile(PathForest);
          end;
          ImgMap.canvas.Draw(I*TileDim, I2* TileDim, Image.Graphic);
        end;
        begin //Buildings.

        end;
      end;
  Image.Destroy;
end;
This code does work (Most of the time), but there is a problem: When the map is redrawn (When its resized etc.), there is white flashing. I tried to solve this with this code, where i first draw everything on a TPicture component:
Code:
procedure TForm2.RepaintMap;
var
  i, i2: integer;
  MaxI, MaxI2: integer;
  Image: TPicture;
  Current: TPicture;
begin
  ImgMap.Canvas.Brush.Color:=clBlack;
  ImgMap.Canvas.Pen.Color  :=clBlack;
  ImgMap.Canvas.Rectangle(0, 0, ImgMap.Width, ImgMap.Height);

  Current:= TPicture.create;
  Image  := TPicture.create;
  MaxI :=MapInfo.Position.X + ImgMap.Width  DIV TileDIM +1;
  MaxI2:=MapInfo.Position.Y + ImgMap.Height DIV TileDIM +1;
  If MaxI  >= MapInfo.Width  Then MaxI :=MapInfo.Width;
  If MaxI2 >= MapInfo.Height Then MaxI2:=MapInfo.Height;
  For I:=MapInfo.Position.x To MaxI -1 Do
    For I2:=MapInfo.Position.Y To MaxI2 -1 Do
      begin
        begin //Landscape.
          Case MapInfo.Tiles[I][I2].Landscape Of
            ltWater:  Image.LoadFromFile(PathWater);
            ltGras:   Image.LoadFromFile(PathGras);
            ltSand:   Image.LoadFromFile(PathSand);
            ltForest: Image.LoadFromFile(PathForest);
          end;
          Current.Bitmap.canvas.Draw(I*TileDim, I2* TileDim, Image.Graphic);
        end;
        begin //Buildings.

        end;
      end;
  ImgMap.Picture:=Current;

  Current.Destroy;
  Image.Destroy;
end;
This results in a black map, with some flashing, and a hanging application.
Any solutions? Thanks
Im using lazarus windows xp.