我试图让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;
答案 0 :(得分: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;