#Hey how to fix that, if i do double click the animation player won't play

15 messages · Page 1 of 1 (latest)

drowsy pecan
#

The animation player self repeats and returns to the first frame every click, maybe its playing but it doesn't have time to walk.

rapid swan
#

It's a bit annoying to go over the code from the video. Try print(movement) at the top of play_anim and watch what it is doing in output.

drowsy pecan
#

alright

#

i do tried print(movement), in the output, if i clicked a key it shows 1, and if not clicked it shows 0, if i do double click it shows 1 multiple and then 0 multiple too until i stop click a key

hushed rivet
#

Can't really understand your script, cause I can't see

drowsy pecan
#

wait a minute

#

thats my script

#

@hushed rivet

rapid swan
#

When you say clicked once, do you mean click and hold down the key? Sorry that was a little unclear. So you need your animation to not reset when spam clicking, what is normally a click and hold animation?

rapid swan
#

This seems a bit advanced, or at least I'm not an expert at it, someone else might answer it better. Does your script stop() the animation somewhere before setting the new one?

/edit sorry I wrote advice for animation player...

drowsy pecan
drowsy pecan
#

ah never mind i'll let it

shut frigate
drowsy pecan
#

ok

rapid swan
#

I wanted to learn animated sprites, so I tried to solve this again. For right movement only to keep it simple:

func _input(event):
    if event.is_action_released("ui_right") and not waiting:
        waiting = true
        %Sprite.frame_progress = 0.4 #Change this to change the delay between transitions
    
func _on_sprite_frame_changed():
    if pos == position:
        %Sprite.animation = "default"
    waiting = false
    pos = position

So on every animation frame it updates pos, which tells it if it has moved or not. It sets the idle animation if it hasn't moved.

The _input section isn't required, but the animation felt too slow/laggy without it. Releasing the move button will hard-set the animation progress for the current frame, which will give a consistent time between stopping and when on_sprite_frame_changed() happens. This could also speed up an animation while tapping, but I didn't notice it too much at low values.

var waiting is to prevent resetting our hard-set frame progress until the next frame has happened, or else we'd get stuck in the same frame when tapping.

I'm not sure how much this applies to your slower, more grid based animations.