I already use my own algorithm, just wanted to see if it was possible to optimize it by comparing other methods …
Oh OK. We don’t have anything special to help with this in CGE.
You usually just have a “target” position (which can be TVector2 in case of 2D games), and “current” position. You can simply subtract them and check, e.g. you know it’s a “move to the right” if Target.X - Current.X > 0.
I use e.g. Player.Load (‘castle-data: /sprite/DownLeft.x3d’);
then Player.PlayAnimation(‘DownLeft’, true);
Maybe I didn’t understand but if I load all the animations at the same time (left, right, up ecc.), only the last one loaded will be available?
I’m not sure what do you mean by “last one loaded will be available”
A single TCastleScene may contain multiple animations (like “move left”, “move right”). At a given moment it plays one animation (the one indicated by PlayAnimation call).
( It is in fact possible to play multiple animations, see simultaneous_animations_one_scene example. But I only mention this for completeness, if is usually not needed, and it requires care when setting up scene information for it to make sense. )
A single scene may even be visible multiple times in the viewport. The simple way to do this is to just add the scene instance multiple times using Viewport.Items.Add(MyScene), although this is also limiting — all instances of MyScene then play the same animation, see Viewport with scenes, camera, navigation | Manual | Castle Game Engine . If it is necessary to instead see the same object multiple times, but with different animation, then you can load it once to TCastleScene (MyScene.Load(...)), and then create more scenes using NewScene := MyScene.Clone(Application);
In this case I should have all the animations in the same spritesheet.
It is indeed usually more comfortable to have one larger scene with multiple animations. It’s easier to manage it this way, as you load it once, and then just use PlayAnimation.