Hi guys!
Currently Im working on some Arkanoid-like project.
I was forced to use Pascal, so I chose Lazarus, but telling the truth I have never written anything graphical in Pascal-like language before.
Now, arkanoid is half-ready , but I have problem with EOutOfMemory in BGRABitmap.
Im using TTimer to draw game current state every 40 ms using function:
procedure TForm1.DrawGame;
var
i, j, k: Integer;
t1,t2,t3,t4,t5: TBGRABitmap;
begin
// rysujemy tlo
bimg := TBGRABitmap.Create(ClientWidth, ClientHeight, BGRAPixelTransparent);
bimg.FillRect(disc_x, disc_y, disc_x+disc_width, disc_y+disc_height, BGRA(255,192,0), dmSet);
bimg.FillRect(0, 0, clientWidth, 40, BGRA(100,100,100), dmSet);
t1 := TBGRABitmap.Create('./graphics/tile_1.png'); t2 := TBGRABitmap.Create('./graphics/tile_2.png'); t3 := TBGRABitmap.Create('./graphics/tile_3.png'); t4 := TBGRABitmap.Create('./graphics/tile_4.png'); t5 := TBGRABitmap.Create('./graphics/tile_5.png');
for i := 0 to 19 do begin
for j := 0 to 18 do begin
if (tiles[i+1][j+1] > 0) then begin
k := tiles[i+1][j+1];
if (k = 1) then begin img := t1; end else if (k = 2) then begin img := t2; end else if (k = 3) then begin img := t3; end else if (k = 4) then begin img := t4; end else begin img := t5; end;
bimg.PutImage(game.tmargin+game.tile_w*j, game.tile_h*i+100,img,dmDrawWithTransparency);
end;
end;
end;
t1.Free; t2.Free; t3.Free; t4.Free; t5.Free;
img := TBGRABitmap.Create('./graphics/ball.png');
bimg.PutImage(ball.x,ball.y,img,dmDrawWithTransparency);
img := TBGRABitmap.Create('./graphics/life.png');
for i := 1 to game.lives do begin
bimg.PutImage(clientWidth-(img.Width+5)*i-5,5,img,dmDrawWithTransparency);
end;
bimg.FontHeight := 30;
//bimg.FontAntialias := true;
//bimg.FontStyle := [fsBold];
bimg.TextOut(5,5,'Poziom: ' + IntToStr(game.level) + ', wynik: ' + IntToStr(game.pts),BGRA(255,255,255));
bimg.Draw(Canvas, 0, 0, True);
bimg.Free;
end;
But the problem is that, at the beginning of game it uses about 6 MB RAM, after 1-2 minutes it goes to about 50-60 MB, a ten crushes causing EOutOfMemoryError.
Would anyone of you be willing to answer me what Im doing wrong and how to fix it?