As i showed in my code (perhaps a bit hidden for you):
A shape does not have a radius, only a width and height (which corresponds to the diameter of the circle).
That means , if the width of your shape is 30 (circle radius becomes 15) then the distances bewteen two shapes should be 30 as well.
i do that in my code with the lines:
Balls[i].Left := x;
x := x - Balls[i].Width;
.. in order to initialize the positions of the shapes.
Then when you animate you would have to change the top positions (b1.top and b2.top) of both your shapes (add to go down, subtract to go up). In case you wish to move the shapes from left to right (or the other way around) then you would need to add/subtract from the shapes left position (b1.left and b2.left)
In case you would want to place your second shape situated at the left of your first shape then your code could look like:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
b2.Left := b1.Left - b1.width;
end;
In case you would want to place your second shape situated at the right of your first shape then your code could look like:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
b2.Left := b1.Left + b1.width;
end;
edit: i've adjusted my example to match you b1 and b2 shapes (which must be placed at design-time on the form). The event s can be added at design-time, so the only thing left for you to do is to match the code.
Btw, i have no idea why you would use a timer at this point inside your code, as you would like to 'move' your shapes by pressing keys (but perhaps i misunderstood the original intention of your code).
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
B1: TShape;
B2: TShape;
procedure FormCreate(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
LCLType;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
// Initialize shapes, positions and widths
const
distance = 30;
var
xpos : Integer = 200;
begin
B1.Shape := stCircle; B2.Shape := stCircle;
B1.Width := distance; B2.Width := distance;
B1.Height := distance; B2.Height := distance;
B1.Top := 100; B2.Top := 100;
B1.Left := xpos;
// Place Shape B2 at left of Shape B1
B2.Left := xpos - B1.Width;
// You could also have written:
// B2.Left := xpos - distance;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
Const
PixelSpeedDistance = 2;
begin
// Move both shapes down PixelSpeedDistance pixels
if (Key = VK_DOWN) then
begin
B1.Top := B1.Top + PixelSpeedDistance;
B2.Top := B2.Top + PixelSpeedDistance;
end
else
// Move both shapes up PixelSpeedDistance pixels
if (Key = VK_UP) then
begin
B1.Top := B1.Top - PixelSpeedDistance;
B2.Top := B2.Top - PixelSpeedDistance;
end;
end;
As you can probably see for yourself: if you have initialized your shapes to match your conditions then there is hardly anything left to code when you want to move your shapes up/down.