Dieser Code läßt dir einen roten Ball in einer Paintbox hin und her fliegen. Ist allerdings wohl etwas stümperhaft, aber Grafik- und Spieleprogrammierung ist nicht meine Stärke.
Delphi-Quellcode:
var
Form1: TForm1;
x, y: Integer;
bleft: Boolean;
implementation
{$R *.dfm}
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
Paintbox1.Canvas.Brush.Color := clRed;
PaintBox1.Canvas.Ellipse(x+Paintbox1.Left,y+Paintbox1.Top,15+x,15);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (x < Paintbox1.Width-15) and (bleft = TRUE) then
x := x+2
else
begin
bleft := FALSE;
x := x-2;
end;
if x <= 0 then
bleft := TRUE;
Caption := IntToStr(x);
PaintBox1.Repaint;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bleft := TRUE;
end;