How can i show 1 frame instead of all of them?

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

Hi guys!
I have a little bug right here and i don’t know how to fix it. Im implementing a dash in my game, i follow tutorial Celeste dash like. The problem i have is that, im using Sprite and AnimationPlayer. And the video is using AnimatedSprite.

basically he just create a scene with a Sprite with a simple script.

  extends Sprite

func _physics_process(_delta):
	modulate.a = lerp(modulate.a,0,0.1)
	if modulate.a < 0.01:

Then he use a packed export in the character.

export (PackedScene) var dash_object

After that, some dash logic and then, In the handle_dash() function, because he has an AnimatedSprite, he use:

if is_dashing:
	var dash_node = dash_object.instance()
	dash_node.texture = ani.frames.get_frame(ani.animation,ani.frame)

But i use, because of the sprite:

if is_dashing:
	var dash_node = dash_object.instance()

In my sprite.texture i have 7 frames, but i couldn’t make to show just one frame, it show all of them. Example

Should i use AnimatedSprite? Is it to posible to fix it with just the sprite?Should i use something else?. I use the documentation, but i couldn’t make it work.

:bust_in_silhouette: Reply From: AlexTheRegent

You can use Animation/HFrames, Animation/VFrames and Animation/Frame or Animation/FrameCoords in editor or corresponding properties hframes, vframes, frame and frame_coords in code to control which frame of the Sprite to show. You can also change these properties in AnimationPlayer too. So it is not necessary to use AnimatedSprite.

I did


But when i made the dash, i get this error.

E 0:00:03.578 set_frame: Index p_frame = 6 is out of bounds (vframes * hframes = 1).
<Fuente C++> scene/2d/sprite.cpp:261 @ set_frame() @ handle_dash() @ _state_logic() @ _physics_process()

MarshaLee | 2021-02-25 15:45

You need to set Animation/HFrames and/or Animation/VFrames too. These parameters tells engine how much frames your spritesheet have. You can’t set frame to value more than hframe * vframe.

AlexTheRegent | 2021-02-26 09:37