-
You could define such “looping and back” animation by editing the XML spritesheet file.
-
You could implement it by running an animation using
MyScene.PlayAnimation(TPlayAnimationParameters)
overload. Run animation as non-looping animation, and assignTPlayAnimationParameters.StopNotification
to run the same animation but this time withTPlayAnimationParameters.Forward
= false. Then again pass aTPlayAnimationParameters.StopNotification
to again run the same animation, this time withTPlayAnimationParameters.Forward
= true. This way you effectively implement “looping” manually, and alternate between “forward” and “backward” playing.See
examples/animations/play_animation/code/gamestatemain.pas
for an example usage ofPlayAnimation
withTPlayAnimationParameters
,
procedure TStateMain.ClickButtonPlayAnimation(Sender: TObject);
var
AnimationName: string;
Params: TPlayAnimationParameters;
begin
AnimationName := (Sender as TCastleButton).Caption;
Params := TPlayAnimationParameters.Create;
try
Params.Name := AnimationName;
Params.Forward := CheckboxForward.Checked;
Params.Loop := CheckboxLoop.Checked;
Params.TransitionDuration := SliderTransition.Value;
Scene.PlayAnimation(Params);
finally FreeAndNil(Params) end;
end;