我想动画一个令牌移动了X次。
在这种情况下,X将是在模具上滚动的数字。
例如,如果一个播放器滚动一个3,我希望看到令牌“移动”到下一个瓷砖,然后400 if后到下一个瓷砖,然后400 if到最后一个瓷砖。
我试过使用TTimer,它可以很好地动画,但是它并没有停止正确的瓷砖上的标记。使用for循环会导致令牌在正确的瓷砖上结束,但没有动画。我只想让TTimer重复自己X次。:)
我的代码如下(使用Delphi 2010):
For循环的:
for i := 1 to iNum + 1 do // iNum is the number rolled
player1.Left := player1.Left + 200; // player1 is the token` For TTimer:
procedure TfrmSnakesNLadders.tmrMoveTimer(Sender: TObject);
begin
player1.Left := player1.Left + 200;
if player1.Left >= 850 then // 850 is the Rightmost Boundary of the token
tmrMove.Enabled := false;
end;发布于 2018-10-08 14:23:53
你没有向我们展示你如何初始化玩家1.对,但是它看起来像是一个边界条件错误,也就是说,你的850值不应该是850。但是要滚动x次,初始化一个类变量并计数它。有点像这样:
class TfrmSnakesNLadders = class( Form )
….
private
fNum : integer
….然后初始化并启动计时器,如下所示
….
procedure TfrmSnakesNLadders.InitMove;
begin
fNum := 0;
tmrMove.Enabled := true;
end;然后用计时器动画
procedure TfrmSnakesNLadders.tmrMoveTimer(Sender: TObject);
begin
player1.Left := player1.Left + 200;
inc( fNum);
if fNum >= iNum then
tmrMove.Enabled := false;
end;https://stackoverflow.com/questions/52704090
复制相似问题