# Sprite control with the new system

**URL:** https://forum.castle-engine.io/t/sprite-control-with-the-new-system/311
**Category:** Uncategorized
**Created:** [March 18, 2021, 8:03pm UTC](https://forum.castle-engine.io/t/sprite-control-with-the-new-system/311 "2021-03-18T20:03:15Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [March 20, 2021, 12:55am UTC](https://forum.castle-engine.io/t/sprite-control-with-the-new-system/311/2 "2021-03-20T00:55:19Z")

</div>

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.

```auto
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;

```

---

_[View the full topic](https://forum.castle-engine.io/t/sprite-control-with-the-new-system/311)._
