Recent

Author Topic: Появление и исчезание фигур на форме в Лазарусе  (Read 11168 times)

Mihail90

  • Newbie
  • Posts: 2
Здравствуйте программисты, помогите пожалуйста. Нужна программа, в которой должен к примеру появляться на форме прямоугольник, который выдвигается из правого края формы, двигаться до левого края и заходить за него, далее появляется новый и также движется, интервал появления между прямоугольниками должен быть разный. Вот такая задача, помогите пожалуйста с ней.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Hello Mihail90,
Welcome to the forum.

Translated using Google Translator:
Quote
Hello programmers, help please. You need a program that, for example, should have a rectangle appearing on the form that extends from the right side of the form, move to the left edge and go behind it, then a new one appears and also moves, the interval of appearance between the rectangles should be different. Here such task, help or assist please with her.

Something like this below? You can download the test.zip for testing.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Timer1: TTimer;
  17.     procedure Button1Click(Sender: TObject);
  18.     procedure FormPaint(Sender: TObject);
  19.     procedure Timer1Timer(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.   PosX: Integer = 350;
  25.   Animating: Boolean = False;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33. procedure TForm1.Timer1Timer(Sender: TObject);
  34. begin
  35.   Form1.Invalidate;
  36. end;
  37.  
  38. procedure TForm1.Button1Click(Sender: TObject);
  39. begin
  40.   case Animating of
  41.     True:  Button1.Caption := 'Click to resume';
  42.     False: Button1.Caption := 'Click to pause';
  43.   end;
  44.   Animating := not(Animating);
  45.   Timer1.Enabled := Animating;
  46. end;
  47.  
  48. procedure TForm1.FormPaint(Sender: TObject);
  49. begin
  50.   if not(Animating) then Exit;
  51.   Canvas.Brush.Color := clForm;
  52.   Canvas.Clear;
  53.   Canvas.Rectangle(PosX, 130, PosX + 20, 150);
  54.   Dec(PosX, 8);
  55.   if (PosX < -30) then PosX := Width + Random(1000);
  56. end;
  57.  
  58. end.

Mihail90

  • Newbie
  • Posts: 2
Many thanks :D!!!

 

TinyPortal © 2005-2018