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
.