Sprite control with the new system

  1. You could define such “looping and back” animation by editing the XML spritesheet file.

  2. You could implement it by running an animation using MyScene.PlayAnimation(TPlayAnimationParameters) overload. Run animation as non-looping animation, and assign TPlayAnimationParameters.StopNotification to run the same animation but this time with TPlayAnimationParameters.Forward = false. Then again pass a TPlayAnimationParameters.StopNotification to again run the same animation, this time with TPlayAnimationParameters.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 of PlayAnimation with TPlayAnimationParameters,

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;