Thema: Delphi Ball bewegen mit Canvas

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.182 Beiträge
 
Delphi 12 Athens
 
#12

Re: Ball bewegen mit Canvas

  Alt 7. Okt 2005, 23:31
Delphi-Quellcode:
if (x >759) and (xmove<0) then
xmove:=-10;
zu
Delphi-Quellcode:
if x >= 759 - 50 then xmove := -10;
if x <= 0 then xmove := +10;

oder in der Initialisierung:
Delphi-Quellcode:
// Variablen initialisieren
x := 0;
y := 0;
xmove := 10;
ymove := 10;

// wenn erwünscht die Ausgangsposition einzeichnen
Image1.Canvas.Pen.Color := clGreen;
Image1.Canvas.Brush.Color := clYellow;
Image1.Canvas.Ellipse(x, y, x + 50, y + 50);
und in der Schleife:
Delphi-Quellcode:
// Löschen
Image1.Canvas.Pen.Color := clWhite;
Image1.Canvas.Brush.Color := clWhite;
Image1.Canvas.Ellipse(x, y, x + 50, y + 50);

// Position ändern
If x < 0 Then xmove := 10
Else If x >= Width - 50 Then xmove := -10;
If y < 0 Then ymove := 10
Else If y >= Heigth - 50 Then ymove := -10;
Inc(x, xmove); // x := x + xmove;
Inc(y, ymove); // y := y + ymove;

// auf neuer Position einzeichnen
Image1.Canvas.Pen.Color := clGreen;
Image1.Canvas.Brush.Color := clYellow;
Image1.Canvas.Ellipse(x, y, x + 50, y + 50);
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat