0 votes

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?

in Engine by (1,571 points)

1 Answer

+1 vote
Best answer

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
by (204 points)
selected by

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

let me know how it turns out?

Hey please, i try make this, but donĀ“t work :(
I'm in the same problem

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.