0 votes

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:
        queue_free()

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()
    dash_node.set_texture(sprite.texture)

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.

Godot version 3.2.3
in Engine by (20 points)

1 Answer

0 votes

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.

by (1,650 points)

I did

        dash_node.set_frame(sprite.get_frame())

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


E 0:00:03.578 setframe: Index pframe = 6 is out of bounds (vframes * hframes = 1).
scene/2d/sprite.cpp:261 @ setframe()
Player.gd:213 @ handle
dash()
PlayerFSM.gd:48 @ statelogic()
StateMachine.gd:12 @ physicsprocess()

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.

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 Frequently asked questions and 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 [email protected] with your username.