Thema: Delphi Timer.Interval<1

Einzelnen Beitrag anzeigen

Martin.Ghosts

Registriert seit: 9. Dez 2005
54 Beiträge
 
Delphi 7 Personal
 
#11

Re: Timer.Interval<1

  Alt 8. Jun 2006, 21:53
Zitat:
Teste doch einfach vorm Verschieben, ob's drüber hinaus geht und verschiebe nach der Abfrage.
(zu Matze) Klar, das könnte man machen. Jedoch wird dann die Wand sehr warscheinlich nicht berührt.

(zu SirThornberry) Hier mal mein Quelltext:
Delphi-Quellcode:
var
  Form1: TForm1;
  x, y: Integer;

implementation

{$R *.dfm}

procedure TForm1.Move;
begin
  Form1.Shape1.Left:= Form1.Shape1.Left + (x);
  Form1.Shape1.Top:= Form1.Shape1.Top + (y);
  if (Form1.Shape1.Left <= 0) then
    x:= (-1) * x;
  if (Form1.Shape1.Top <= 0) then
    y:= (-1) * y;
  if ((Form1.Shape1.Left + Form1.Shape1.Width) >= Form1.Width) then
    x:= (-1) * x;
  if ((Form1.Shape1.Top + Form1.Shape1.Height) >= Form1.Height) then
    y:= (-1) * y;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x:= -1;
  y:= -1;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Form1.Move;
end;

end.
Wenn ich dich richtig versehe meinst du es so:
Delphi-Quellcode:
var
  Form1: TForm1;
  x, y, count: Integer;

implementation

{$R *.dfm}

procedure TForm1.Move;
begin
  Form1.Shape1.Left:= Form1.Shape1.Left + (x);
  Form1.Shape1.Top:= Form1.Shape1.Top + (y);
  if (Form1.Shape1.Left <= 0) then
    x:= (-1) * x;
  if (Form1.Shape1.Top <= 0) then
    y:= (-1) * y;
  if ((Form1.Shape1.Left + Form1.Shape1.Width) >= Form1.Width) then
    x:= (-1) * x;
  if ((Form1.Shape1.Top + Form1.Shape1.Height) >= Form1.Height) then
    y:= (-1) * y;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  x:= -1;
  y:= -1;
  count:= 0;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if (count = 25) then
    begin
      count:= 0;
      Form1.Move;
    end
  else
    count:= count + 1;
end;

end.
Dadurch bewegt sich der Ball jedoch nochmal deutlich langsamer.
  Mit Zitat antworten Zitat