Programming => Graphics and Multimedia => Graphics => Topic started by: ITomi on January 19, 2021, 10:14:02 am

Title: Problem with scrolling image
Post by: ITomi on January 19, 2021, 10:14:02 am
Hello everybody!

I'm still new here and in the world of Lazarus.
I started to develop a game, in which there is a larger bitmap on the Form1. You can move this bitmap with the arrow buttons.
But I have a big problem with this: I can't delete the graphical elements from the previous places, and so these pull a strip as you can see on the attached image.
How can I delete the graphical components from the previouis places? The invalidate; command doesn't work with it.

Pieces from my code:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   width:=Screen.width;
  4.   height:=Screen.height;
  5.   palyakep:=TBitmap.Create;
  6.   palyakep.SetSize(width*2,height*2);
  7.   palyakep.canvas.brush.color:=clblue;
  8.   palyakep.canvas.fillrect(0,0,width*2,height*2);
  9. (...)
  10.   palyafrissito:=TTimer.Create(nil);
  11.   palyafrissito.interval:=10;
  12.   palyafrissito.ontimer:=@palyafrissites;
  14. procedure TForm1.palyafrissites(Sender: TObject);
  15. begin
  16. //figures moving...
  17. with palyakep.canvas do invalidate;
  19. procedure TForm1.FormPaint(Sender: TObject);
  20. var puffalkepe: byte;
  21.   i: integer;
  22. begin
  23.   canvas.draw(palyakepx,palyakepy,palyakep);
  24.   for i:=0 to puffancsdb-1 do
  25.   begin
  26.     puffalkepe:=trunc(puffancs[i].iranya*8/360);
  27.     if puffalkepe>7 then puffalkepe:=0;
  28.     palyakep.canvas.draw(puffancs[i].xhely,puffancs[i].yhely,puffancskep[puffalkepe]);
  29.   end;
  30. end;
Title: Re: Problem with scrolling image
Post by: Handoko on January 19, 2021, 02:37:59 pm
Hello ITomi,
Welcome to the forum.

Glad to find someone who is interested to develop games here. I want to provide you a detailed answer, unfortunately I'm a bit busy at the moment.

You can download some simple demos, especially Pong Game, Game Map Editor, Simple Animation, Bullet and Asteroid Collision Detection, Moving Circles, Move a Shape With a Mouse on the Graphics category in the link below. Those should provide you some basic knowledge how to create games using Lazarus: (

Have fun!
Title: Re: Problem with scrolling image
Post by: ITomi on January 20, 2021, 01:27:50 pm
Hello and thanks, Handoko!
I didn't know that "HowTo Demos" portal yet, but I will look it.
Till this moment, I have only one small game written in Lazarus, and it can be found on my website: (
This is a simple space shooter: "Space defender".
But now I would like make a real time strategy game, therefore I should know the technique to how can I draw images on a canvas bigger than canvas of TForm1.
Title: Re: Problem with scrolling image
Post by: Handoko on January 21, 2021, 03:57:58 am
Your Space Defender looks good. Please consider to showcase it on the wiki page:

Did you draw the graphics yourself?

For the original issue, I remember there was a similar case. Maybe this thread can be useful to you:,43985.msg308825.html#msg308825
Title: Re: Problem with scrolling image
Post by: ITomi on January 21, 2021, 09:18:56 am
Thank you, Handoko!  :D
The graphics origins from an old good shoot'em up game called "Tyrian".
And thanks for your link! It seems to be similar problem like mine. I look closely it.
TinyPortal © 2005-2018