Learning to use new Sprite method

This seems like it doesn’t detect the project data correctly. (see Data directory | Manual | Castle Game Engine ) Based on your screenshots, it looks like you should have a CastleEngineManifest.xml file that defines your project in f:/Game Development/Rescue Island 01-03-2021/ .

Then everything should work.

In the editor, if you open a project there (that is, you open f:/Game Development/Rescue Island 01-03-2021/CastleEngineManifest.xml) it should work, and even automatically change URLs you open inside data/ into URLs like castle-data:/....

If this advise doesn’t help, you need to send us a simple project to reproduce your problem.

Notice: on your screenshot I can see you have URL = file:///F:/Game... which is not good (and you most probably seen a warning when opening it) because it will not work on other people’s machines. It should change to castle-data:/... URL if you open it again, with proper CastleEngineManifest.xml to define your project.

Note 2: If you hope to distribute the game to Linux users, remember to also pay attention to the upper/lower case of the letters, I recall I mentioned it before :slight_smile: You have a folder called Locations. On Windows (more precisely, on case-insensitive filesystem) you can call it Locations or locations or lOcAtIonS and it doesn’t matter. On Linux (more precisely, on case-sensitive filesystem) you must always refer to it exactly Locations, so castle-data:/Locations/... not castle-data:/locations/...

And how can I use the PlayAnimation to play the images of the spritescreen?
This is part of the xml file:

Open this file with view3dscene, e.g. by double-clicking on the JohnWalkLeft.starling-xml . Open the animations panel then (click the “Animations” button) it will show the list of animations, and you can play them. The names shown there will be names you can use with PlayAnimation. Looking at your file, PlayAnimation('JohnWalkLeft-').

Alternative: adjust the AutoAnimation property of the TCastleScene in the editor. It shows you available animations.

Also: make sure you use the latest CGE from https://castle-engine.io/ . We had a bug with anchors (like #fps:45) on Windows some time ago – it was fixed.

I have the latest CGE (alpha 7).
I switched off the #fps:45 for now to exclude this as an error on loading.

The notification shows the right path of the XML.
It is the same as the .png file that loads correctly.

When I try to load it in View3dscene it adds another .xml.

I checked the name in a console window.

So maybe it is in the name after all but I don’t see it.

It means that your actual filename is JohnWalkLeft.starling-xml.xml (instead of JohnWalkLeft.starling-xml). You have in Windows file explorer the option “Hide extensions of known file types”, so the mistake wasn’t evident from your previous screenshots. See the Internet, e.g. here Show and hide file extensions in Windows 10 , on how to turn it off.

Note that in the CGE editor “Files” (panel at the bottom) you should have seen the actual filename with extension (we do not hide any extensions there).

Use “rename” to make it really JohnWalkLeft.starling-xml.

Yes, that did it. :slight_smile:
So I had to remove the .xml extension.

Now the first sprite cell is showing up on the background.
The animation list in View3dscene shows the 60 sprites of the sheet as separate animations but they are 60 sprites, not animations. So how can I loop them / playing them from sprite 0 to 59 with the PlayAnimation command?

Another thing is I get an error whenI try to compile from the editor:

The .lpr is missing?

The name of the animation is separated by - with the frame number, instead of underscore as required by Starling. Following Sprite sheets · castle-engine/castle-engine Wiki · GitHub , you have to use the anim-naming:trailing-number option in the URL. Together with FPS it looks like this:


You can test it in view3dscene by opening such URL in the view3dscene open box. It will open my_sprite_sheet.starling-xml and apply the indicated options.

The .lpr is missing?

How do you compile the project so far? I’m guessing Rescue_Island.pas is your main program file. If that it the case, edit CastleEngineManifest.xml (see CastleEngineManifest.xml examples · castle-engine/castle-engine Wiki · GitHub for lots of examples) and put there standalone_source="Rescue_Island.pas" ,

I really don’t get it.
Do I need to change the filename of the xml file?

I now have:

AnimScene.Load(‘castle-data:/locations/JohnWalkLeft.starling-xml#fps:45, anim-naming: trailing-number’);
AnimScene.PlayAnimation(‘JohnWalkLeft-’, true);

Or is it AnimScene.Load(‘castle-data:/locations/JohnWalkLeft.starling-xml#fps:45, anim-naming: trailing number 0, 1, 2, 3’);

I get no runtime errors that would indicate where I am wrong. I really need a running example of this new sprite playing method.

Thanks, I can compile now from the editor.

The syntax I shown was an example URL. You do not rename the file (it stays just JohnWalkLeft.starling-xml), you only append additional options to this URL. So it should be:

AnimScene.PlayAnimation('JohnWalkLeft-', true);

Or use CGE editor (much advised):

  • set URL of the scene to castle-data:/locations/JohnWalkLeft.starling-xml#fps:45,anim-naming:trailing-number

  • set AutoAnimation to JohnWalkLeft- (once you set the URL, the AutoAnimation is a combobox that should show this as available animation name)

There are no extra spaces, no extra numbers. I you use an invalid anchor in the URL, you should get an exception clearly stating so. See the docs on Sprite sheets · castle-engine/castle-engine Wiki · GitHub .

The examples of it, as well as new sprite sheet editor that in practice will avoid the need for such anchors in URL, will come shortly ( Sprite Sheet Editor with our own format castle-sprite-sheet by and3md · Pull Request #248 · castle-engine/castle-engine · GitHub ).

As far as I can see that is exactly what I had but now I copied and pasted your lines it instantly worked, shoot me. :slight_smile:

It appears to me with Viewports and Scenes I do not need all my Windowbase code, TDrawable images, rendering and updating routines anymore for displaying things, resulting in much less code?
Can you advise me on changing my old Windowbase code with all the stuff to scenes or could I just use Viewports and scenes with the same size as the sprites just for displaying them on existing TDrawable Image backgrounds?
For now:How can I display the mouse cursor again on the viewport (or scene?).

Thanks for your help, patience and badge. :wink:


Yes, I’d say you should now render all sprites and images using TCastleScene. No more need to use TDrawableImage. This way you can also design it visually in the editor, it should be simpler.

The TCastleViewport has a Cursor property like other UI controls. Just set it as needed. See Castle Game Engine: CastleUIControls: Class TInputListener .