Sprite control with the new system

With the new sprite system I hope to get more control over the sprite animations and possibilities.

Question 1:
How can I play a sprite sheet from images 0-59 and then back from 59-0 so it loops forward and back? This makes sense to me so I can play a “stand idle animation”.
I probably could do it by changing the xml spritesheet but I would prefer more control over playing a range or sequence of images from a sprite sheet than playing just the list from 0-59 images.

  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;