So I have a Player which is a TCastleScene that contains my Player.castle-sprite-sheet. I have an Idle animation and another Idle animation when holding a weapon except both the weapon and character are moving so for example If I want to swing a sword or fire a weapon I can’t simply attach a transform and have it follow the sprite animation or can I?
Which led me to valterb asking Play a certain animation from a sprite sheet - Castle Game Engine Forum (castle-engine.io)
TSprite contains all the necessary info I need to move another object parallel with my sprite animation based on the Frame position/index though unless there is a better way to simply access the TSprite directly from TCastleScene, would be much appreciated or better yet any better methods?
Note about TSprite: It is deprecated, and I would definitely advise to not use it in newer games.
TSprite has a few disadvatages — you have to control manually drawing it, so you manually have to manage rendering order, it cannot be affected by physics, it cannot be seen in editor, it is not part of Viewport.Items hierarchy of TCastleTransform, you have to manually manage it’s scale etc.
The new way to use sprites, through TCastleScene, following Sprite Sheets | Manual | Castle Game Engine , is much better The TCastleScene does not have any TSprite internally, it renders and animates sprites by setting up X3D nodes.
From what I understand, you need to know the current animation of sprite sheet and the time within it.
-
You can get the animation using MyScene.CurrentAnimation
, if it’s non-nil then:
-
MyScene.CurrentAnimation.X3DName
contains the name,
-
and the MyScene.CurrentAnimation.ElapsedTimeInCycle
contains the time within the animation.
-
You can then synchronize another scene to this, e.g. using MyOtherScene.ForceAnimationPose(...)
.
1 Like
The above is what I needed with syncing animations though I also need the sprite to move with another sprite based on XY cord so the animation on click can begin at 0 always.
Gif below for more detail.
I could make the weapon effect animation move as I did with the weapon moving with my playersprite Using
SceneWeapon.ForceAnimationPose(‘PlayerWalking’,
ScenePlayer.CurrentAnimation.ElapsedTimeInCycle, True); but when I shoot the frame needs to begin at 0 for a smooth effect. In doing so it will reset the pos of the effect causing it to not be in sync like the gif above I’m really not sure how I can simply resolve this other than making my animation lock unless there is a way to convert ElapsedTimeInCycle double to XY cords for my transform holding the effect sprite
Edit: I will try work around this issue and change the animation effect not rely on aligning with the barrel of the gun & when it comes to the bullet I will spawn it in at a fix pos and see how that goes
I am not clear why these 2 things (synchronizing animation time for weapon effect and setting position for the weapon effect) conflict
How do you set the position of weapon effect? I mean my first attempt at this would be to just set WeaponEffectScene.Translation := ...
, and the exact translation needs to have coded rules (what translation is proper in each animation/frame), since there’s no information about “current weapon position” in the player character sprite.
A much more involved alternative would be to have animation using bones (transformations), and then attach the weapon effect as a child transform, as we do in example examples/animations/expose_transformations_to_animate_children/
. While this gives control to gfx assets, it is also more involved, as it means one has to prepare an animation animation using bones (transformations, “armature” in Blender) that reflects the sprite sheet animation perfectly.
1 Like
The conflict I mention is because the weapon movements are sprite animations I simply wasn’t thinking straight as you mention there’s no information about “current sprite animation position so it will be a case of coded rules" or as also mention bones, though instead I’m working around the sprite animation movements instead shown here:
Sprite effect is at a fixed position attached to the player weapon looks clean enough
1 Like