# Problems using the #fps parameter with a starling-xml file

**URL:** https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318
**Category:** Uncategorized
**Created:** [April 2, 2021, 9:59am UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318 "2021-04-02T09:59:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![valterb](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/valterb/32/26_2.png) [@valterb](https://forum.castle-engine.io/u/valterb)
#### Post date: [April 2, 2021, 9:59am UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/1 "2021-04-02T09:59:29Z")

</div>

I use:  
`MyAnim.Load(MyStarlingXml+'#fps:30,anim-naming:strict-underscore')` (or even `URL`) to open a spritesheet.  
Any parameter I insert after `#fps` does not change the number of frames which always remains the default (8).  
Maybe I’m wrong but I don’t think it’s needed to disable `DefaultSpriteSheetFramesPerSecond`.  
Only `TimePlayingSpeed` works with which I can change the speed of the animation but always starting from 8 frames / sec.  
I tried to launch the animation both with `PlayAnimation` and by setting `AutoAnimation` and `AutoAnimationLoop` but nothing changes.  
I use TCastleControlBase with Lazarus. Could this be the problem?

So I tried the code posted by @Carring

> [@Working with Scenes and Sprites](https://forum.castle-engine.io/t/working-with-scenes-and-sprites/307/5):
>
> Ok, I got it working, here is the complete code. But maybe it can be more compact, for instance the procedure StopWalk. I found it cumbersome to repeatedly have to switch off animations on changing sprite screens so I’m open for suggestions on improvement. update: (edited and moved to topic: “Collision Course”

using my sprite sheets and the #fps parameter works fine. But it uses CastleWindow.

I created a new application by removing all unnecessary code:

```
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  CastleControl, CastleScene, CastleViewport, CastleTransform, CastleVectors;

type
  TPlayer = class
    constructor Create;
    destructor Destroy; override;
  end;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    CastleControlBase1: TCastleControlBase;
    procedure Button1Click(Sender: TObject);
  private

  public
    MainViewport: TCastleViewport;
    PlayerScene: TCastleTransform;
  end;

var
  Form1: TForm1;
  player: TPlayer;
  PlayerAnimations: TCastleScene;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  MainViewport := TCastleViewport.Create(Application);
  MainViewport.AutoCamera := true;
  MainViewport.FullSize := true;
  MainViewport.Setup2D;
  MainViewport.Camera.Orthographic.Width := castlecontrolbase1.ClientWidth;
  MainViewport.Camera.Orthographic.Height := castlecontrolbase1.ClientHeight;
  MainViewport.Camera.Orthographic.Origin := Vector2(0.5, 0.5);

  CastleControlBase1.Container.Controls.InsertFront(MainViewport);

  Player:= TPlayer.Create;
  PlayerScene := TCastleTransform.Create(Application);
  PlayerAnimations := TCastleScene.Create(Application);
  PlayerAnimations.URL:=[MyStarlingXml]+'#fps:25,anim-naming:strict-underscore';
  //PlayerAnimations.Load([MyStarlingXml]+'#fps:3,anim-naming:strict-underscore'); 
  PlayerAnimations.ProcessEvents := true;
  PlayerScene.Add(PlayerAnimations);
  PlayerAnimations.Exists:=true;
  PlayerScene.Translation := Vector3(0, 0, 1);
  MainViewport.Items.Add(PlayerScene);
  PlayerAnimations.PlayAnimation('Down', true);
  //PlayerAnimations.AutoAnimation:='Down';
  //PlayerAnimations.AutoAnimationLoop:=true;
end;

constructor TPlayer.Create;
begin
  inherited;
end;

destructor TPlayer.Destroy;
begin
  inherited;
end;

end.

```

The frame number of the animation never changes.  
Some idea?

---

<div class="post-metadata">

### Author: ![Carring](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/carring/32/1950_2.png) [@Carring](https://forum.castle-engine.io/u/Carring)
#### Post date: [April 3, 2021, 3:37pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/2 "2021-04-03T15:37:58Z")

</div>

Hi Valterb,

Today I have improved my uploaded code in the “Collision Course” topic, it works fine, please take a look.  
I don’t quite understand your question about changing the number of frames.  
If you want to display certain single images from a spritescreen, use “strict-underscore” but if you want to display a range or looping animation use “trailing-number”. (see my code).

---

<div class="post-metadata">

### Author: ![kagamma](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/kagamma/32/226_2.png) [@kagamma](https://forum.castle-engine.io/u/kagamma)
#### Post date: [April 3, 2021, 4:12pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/3 "2021-04-03T16:12:20Z")

</div>

I just test your code and it works fine. The speed changes according to fps value: [2021-04-03 23-09-08](https://streamable.com/86kwqd)

---

<div class="post-metadata">

### Author: ![valterb](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/valterb/32/26_2.png) [@valterb](https://forum.castle-engine.io/u/valterb)
#### Post date: [April 3, 2021, 6:19pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/4 "2021-04-03T18:19:38Z")

</div>

@kagamma Thanks for trying my code. I discovered that the reason for this strange behavior depends on the string I use to indicate the starling-xml file. Using “c: \ …” the #fps parameter is ignored, using “castle-data” works fine. I don’t understand why.

---

<div class="post-metadata">

### Author: ![valterb](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/valterb/32/26_2.png) [@valterb](https://forum.castle-engine.io/u/valterb)
#### Post date: [April 3, 2021, 6:46pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/5 "2021-04-03T18:46:38Z")

</div>

@kagamma I made a video showing how the #fps parameter works with “castle-data” and fails with the full path.

---

<div class="post-metadata">

### Author: ![valterb](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/valterb/32/26_2.png) [@valterb](https://forum.castle-engine.io/u/valterb)
#### Post date: [April 3, 2021, 6:56pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/6 "2021-04-03T18:56:28Z")

</div>

As suggested on Discord by @and3md it is needed to add before the full path “file:///”.

---

<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: [April 7, 2021, 11:37pm UTC](https://forum.castle-engine.io/t/problems-using-the-fps-parameter-with-a-starling-xml-file/318/7 "2021-04-07T23:37:56Z")

</div>

Cool, I see this was resolved. I’ll also mention here (also mentioned in [2d dragon missing? - #11 by michalis](https://forum.castle-engine.io/t/2d-dragon-missing/314/11) ) that, since yesterday, we actually have even better answer:

Use `.castle-sprite-sheet` format instead of Starling, that can be created/edited within the CGE editor itself. Then the FPS can be configured inside the sprite sheet file, and it can even be different for each animation. This avoids using the `#fps...` anchor at all.

There will be a big news post about it this weekend 🙂 For now see docs on [Sprite sheets · castle-engine/castle-engine Wiki · GitHub](https://github.com/castle-engine/castle-engine/wiki/Sprite-sheets) and short example in `examples/sprite_sheets/sprite_sheets_demo/`.
