0

我试图让 TCanvas 向上移动一点,然后再向下移动。但是使用当前代码,它执行得如此之快,以至于您看不到它。希望有人能给我正确的方法来做到这一点..

    {this will give the attack amimation}
procedure TGameData.AnimateAttack(slot: Integer);
begin
   if slot = 1 then
   begin
     fgame.slot1.Top := fgame.slot1.Top - 9;
     fgame.slot1.Repaint;
     fgame.slot1.Top := fgame.slot1.Top + 9;
     fgame.slot1.Repaint;
   end;
   if slot = 2 then
   begin
     fgame.slot2.Top := fgame.slot2.Top - 9;
     fgame.slot2.Repaint;
     fgame.slot2.Top := fgame.slot2.Top + 9;
     fgame.slot2.Repaint;
   end;
   if slot = 3  then
        begin
     fgame.slot3.Top := fgame.slot3.Top - 9;
     fgame.slot3.Repaint;
     fgame.slot3.Top := fgame.slot3.Top + 9;
     fgame.slot3.Repaint;
   end;
   if slot = 4 then
        begin
     fgame.slot4.Top := fgame.slot4.Top - 9;
     fgame.slot4.Repaint;
     fgame.slot4.Top := fgame.slot4.Top + 9;
     fgame.slot4.Repaint;
   end;
   if slot = 5  then
        begin
     fgame.slot5.Top := fgame.slot5.Top - 9;
     fgame.slot5.Repaint;
     fgame.slot5.Top := fgame.slot5.Top + 9;
     fgame.slot5.Repaint;
   end;
   if slot = 6 then
        begin
     fgame.slot6.Top := fgame.slot6.Top - 9;
     fgame.slot6.Repaint;
     fgame.slot6.Top := fgame.slot6.Top + 9;
     fgame.slot6.Repaint;
   end;



end;
4

1 回答 1

2

存储当前动画帧数并使用计时器来制作动画。像这样:

FFrameNumber := 0;
FTimer : = TTimer.Create(Self);
FTimer.Interval := Round (1.0 / FrameRate);
FTimer.OnTimer := AnimationHandler;

...

FFrameNumber := 0;
FTimer.Enabled := True;   // start the animation

...

procedure AnimationHandler(Sender : TObject)
begin
FTimer.Enabled := False;
case FFrameNumber of
  0 : // set the canvas position
  1 : // set the canvas position
  2 : // set the canvas position
  ...
end;

Inc(FFrameNumber);   // next frame

if (FFrameNumber < FrameCount) then
  FTimer.Enabled := True;   
end;
于 2013-11-13T12:31:25.487 回答