The title is bad so i will explain:
Hi, i created 4 images, in which the character (game character, a car) looks at different directions, every time you press the arrow keys (up looks at up, down looks at down, left looks at left, right looks at right), here is the code:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var path,dleft,dright,dtop,dbot:string;
begin
path:=paramstr(0);
dleft:=extractfilepath(path)+'Images\Pacman_Left.bmp';
dright:=extractfilepath(path)+'Images\Pacman_Right.bmp';
dtop:=extractfilepath(path)+'Images\Pacman_Top.bmp';
dbot:=extractfilepath(path)+'Images\Pacman_Bot.bmp';
case Key of
VK_UP:
begin
image6.Picture.LoadFromFile(dtop);
image6.Top := image6.Top - 10;
end;
VK_DOWN:
begin
image6.Picture.LoadFromFile(dbot);
image6.Top := image6.Top + 10;
end;
VK_LEFT:
begin
image6.Picture.LoadFromFile(dleft);
image6.Left := image6.Left - 10;
end;
VK_RIGHT:
begin
image6.Picture.LoadFromFile(dright);
image6.Left := image6.Left + 10;
end;
end;
end;
I think the code i am using is terrible, because if i press a key over than a time, it will reload the image and it will keep doing it as long as i keep pressing the same key, such a waste of ram. What can i do about it? thanks