Thema: Delphi Animation mit TImage!

Einzelnen Beitrag anzeigen

Ag3nt

Registriert seit: 3. Jun 2003
28 Beiträge
 
#16
  Alt 6. Jun 2003, 02:02
Also hier hab ich mal einen Code der einen Käfer FLACKERFREI über einen Hintergrund laufen läßt. Kannst du mir bei dem Code bischen Helfen?

Delphi-Quellcode:
procedure TForm1.Kaeferanimation;
var
    Temp: TBitmap;
    KaeferArray, NegativArray : array [1..4] of TBitmap;
    xmirror, ymirror : shortint;
    x, y, idx : integer;
begin
    xmirror := 1;
    ymirror := 1;
    y := 1;
    idx := 1;
    Temp := TBitmap.create;
    Temp.Width := 42;
    Temp.Height := 42;
    For x := 1 to 4 do
    begin
      KaeferArray[x] := TBitmap.create;
      NegativArray[x] := TBitMap.create;
      KaeferArray[x].Width := 40;
      NegativArray[x].width := 40;
      KaeferArray[x].Height := 40;
      NegativArray[x].Height := 40;
    end;
    x := 1;
      
    Kaeferarray[1].LoadFromFile('Bilder\ru.bmp');
    Kaeferarray[2].LoadFromFile('Bilder\ro.bmp');
    Kaeferarray[3].LoadFromFile('Bilder\lo.bmp');
    Kaeferarray[4].LoadFromFile('Bilder\lu.bmp');
    NegativArray[1].LoadFromFile('Bilder\nru.bmp');
    NegativArray[2].LoadFromFile('Bilder\nro.bmp');
    NegativArray[3].LoadFromFile('Bilder\nlo.bmp');
    NegativArray[4].LoadFromFile('Bilder\nlu.bmp');
  
    try

    While isrunning do begin
        sleep(Scrollbar1.Position);
        x := x + 1 * (xmirror);
        y := y + 1 * (ymirror);
        
        BitBlt(Temp.Canvas.Handle, 0, 0, 42, 42, bg.Canvas.Handle, x, y, SRCCOPY);
        BitBlt(Temp.Canvas.Handle, 1, 1, 40, 40, Negativarray[idx].Canvas.Handle, 0, 0, SRCAND);
        BitBlt(Temp.Canvas.Handle, 1, 1, 40, 40, Kaeferarray[idx].Canvas.Handle, 0, 0, SRCINVERT);
        BitBlt(Paintbox1.Canvas.Handle, x, y, 42, 42, Temp.Canvas.Handle, 0, 0, SRCCOPY);

        If (y + 40 > Paintbox1.Height) or (y <= PaintBox1.Top) then
        begin
          ymirror := ymirror * (-1);
          if (xmirror = 1) and (ymirror = 1) then
           idx := 1
          else
          if (xmirror = 1) and (ymirror = -1) then
           idx := 2
          else
          if (xmirror = -1) and (ymirror = -1) then
           idx := 3
          else
          if (xmirror = -1) and (ymirror = 1) then
           idx := 4
        end
        else

        If (x + 40 > PaintBox1.Width) or (x <= PaintBox1.Left) then
        begin
          xmirror := xmirror * (-1);
          if (xmirror = 1) and (ymirror = 1) then
           idx := 1
          else
          if (xmirror = 1) and (ymirror = -1) then
           idx := 2
          else
          if (xmirror = -1) and (ymirror = -1) then
           idx := 3
          else
          if (xmirror = -1) and (ymirror = 1) then
           idx := 4;
        end;
        Application.ProcessMessages;
    end;
   finally
     Temp.Free;
     For x := 1 to 4 do
     begin
       KaeferArray[x].Free;
       NegativArray[x].Free;
     end;
   end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
Jpg:TjpegImage;
begin
 Bg := TBitmap.Create;
 Jpg := TJpegImage.Create;
 try
   jpg.LoadFromFile('Bilder\Background.jpg');
   Bg.Assign(Jpg);
 finally
   Jpg.Free;
 end;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
 BitBlt(Paintbox1.Canvas.Handle, 0, 0, 360, 245, Bg.Canvas.Handle, 0, 0, SRCCOPY);
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 isrunning := not isrunning;
 If isrunning then SpeedButton1.Caption := 'Stop'
  else
 SpeedButton1.Caption := 'Start';
 BitBlt(Paintbox1.Canvas.Handle, 0, 0, 360, 245, Bg.Canvas.Handle, 0, 0, SRCCOPY);
 Kaeferanimation;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Bg.free;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  isrunning := not CanClose;
end;

end.
Wie kann ich ihn bei meiner simplen Animation verwenden?
Gruß, Ag3nt
  Mit Zitat antworten Zitat