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

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

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?

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).

I just test your code and it works fine. The speed changes according to fps value: 2021-04-03 23-09-08

@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.

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

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

Cool, I see this was resolved. I’ll also mention here (also mentioned in 2d dragon missing? - #11 by michalis ) 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 :slight_smile: For now see docs on Sprite sheets · castle-engine/castle-engine Wiki · GitHub and short example in examples/sprite_sheets/sprite_sheets_demo/.