0 votes

I animated a TextureRect (black square) which comes from below the screen and disappears the same way (in AnimationPlayer: the TextureRect goes from one position to another). I want it so when holding a button (ex.: RMB) the animation plays and the TextureRect appears (comes up from below the screen via AnimationPlayer) and stays there as long as I'm holding down the button. And when I release the button, the TextureRect disappears with the corresponding animation (goes back, down below the screen via AnimationPlayer).

So far, I used this code so the TextureRect just appears and disappears but now I need it to do the same with animation.

    if Input.is_action_pressed("aim"):
    $black_box.visible = true
else:
    $black_box.visible = false
Godot version v3.3.2
in Engine by (46 points)

1 Answer

0 votes
if Input.is_action_just_pressed("aim"):
    $black_box.visible = true
    $animationplayer.play("slide")
elif Input.is_action_just_released("aim"):
    $black_box.visible = false
    $animationplayer.play_backwards("slide")

With "slide" being the name of your animation

by (6,934 points)
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.