Delphi 如何减慢运动速度
我正试图使TCanvas向上移动一点,然后再向下移动。但在当前的代码中,它运行得如此之快,以至于你看不到它。希望有人能给我正确的方法Delphi 如何减慢运动速度,delphi,delphi-xe2,Delphi,Delphi Xe2,我正试图使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.
{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;
存储当前动画帧编号,并使用计时器制作动画。像这样:
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;
FFrameNumber:=0;
FTimer:=TTimer.Create(Self);
FTimer.Interval:=圆形(1.0/帧速率);
FTimer.OnTimer:=AnimationHandler;
...
f帧编号:=0;
FTimer.Enabled:=True;//启动动画
...
过程AnimationHandler(发送方:ToObject)
开始
FTimer.Enabled:=False;
个案数目
0://设置画布位置
1://设置画布位置
2://设置画布位置
...
结束;
公司(FFrameNumber);//下一帧
如果(FFrameNumber
您需要使用某种延迟调整+重新喷漆才能使其正常工作。此时,每次只需移动画布/重新绘制,因此没有“渐进”移动。查看这些使用计时器的,以及其他使用XE2附带的内置动画的。使用TTimer
更新位置。但总的来说,我不会用控件来画你的画。直接在画布上画画。我直接在画布上画画,我只是想让整个画布上下移动。你说的画布是指画框?或者你在画什么画布?不管你的问题是什么,这看起来都是解决问题的错误方法。当然,所有的顶级洗牌和重画调用都是错误的。