How to get an animation's current frame?

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

I am trying to create a particle effect using the current frame of an animation in Godot 3.0. I want the particle’s texture to be the current frame of my animation.

I use an AnimationPlayer rather than an AnimatedSprite for my animations. Each animation is key framed from a spritesheet which is loaded as the sprite’s texture.

I tried using the following to set my Particles2D texture:

texture = player.get_node("Sprite").texture

but it assigned the particle the player’s entire spritesheet, rather than the current frame of it.

How can I create a reference to my sprite’s current frame and not its whole spritesheet texture?

:bust_in_silhouette: Reply From: gswashburn

If you use the same spritesheet in the particles2D as your sprite.
pseudocode:
Assign same sprite sheet to the sprite with animation player and particles2d texture
Get the current frame of the sprite
Set the particles2d process material offset to value based on sprite frame

func _ready():	
	$Particles2D.restart()

func _process(delta):
	var player_frame = $Player/Sprite.frame # current frame of sprite animation
	var offset = player_frame *.100 # Play with this to get correct frame for particle
	$Particles2D.process_material.set("anim_offset",offset) # offset is equivalent of frame in particles2d Animation

Interesting idea. I will try it out later. I imagined there would be a more direct way to do it.

Diet Estus | 2018-04-01 19:20

let me know how it turns out?

gswashburn | 2018-04-01 20:18

Hey please, i try make this, but don´t work :frowning:
I’m in the same problem

Amigoimaginario | 2019-07-25 20:12