How do I get the current sprite playing in the animation player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rousbound

Thanks in advance

:bust_in_silhouette: Reply From: Asthmar

$Animationplayer.play(‘animation_name’)

Sorry if I was not clear. My question was meant to understand how can I get the sprite currently playing in the animation player.

If the animation “running” has 5 frames, and it is right now on the third frame, how can I get the third frame in the form of a Sprite object?

I was looking for something like:

$AnimationPlayer.get_current_frame_sprite()

rousbound | 2021-07-14 00:28

Okay I see. If you are using a spritesheet then this is not possible as far as I know. The animationplayer is just animating the texture, Its not turning it into a sprite node. Though if you use an animated sprite there is a get_frame( ) function for that node.

But if your are trying to get a certain frame to make something happen, then the animation player can call functions on a specfic frame. Its a very powerful node in that aspect. Not sure if that clears things up

Asthmar | 2021-07-14 02:03

Yes it is possible, found it on this video: https://www.youtube.com/watch?v=SnvdvnJUYxE

Basically you do pass to a sprite object the hframe vframe frame and texture:

otherSprite.texture = $Sprite.texture
otherSprite.vframes = $Sprite.vframes
otherSprite.hframes = $Sprite.hframes
otherSprite.frame = $Sprite.frame
otherSprite.scale = self.scale

rousbound | 2021-07-15 03:26