The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

I just started learning Godot and i don't have enough knowledge to make a big piece of my ideas. I have a Sprite of a tree in a pot, and i want to make this Sprite possible to cover my character, like he is behind Sprite, but ONLY when 'ui_down' action is pressed. Thanks for your future anwers ;P

in Engine by (13 points)

1 Answer

0 votes

Let's assume you have following tree structure:

  • Node2D
    |---- Sprite1 (Player)
    |---- Sprite2 (Tree)

You could create a script in the Node2D node with:

func _process(delta):
    if Input.is_action_pressed("ui_down"):
        if not $Sprite2.visible:
            $Sprite2.visible = true
        $Sprite2.position = $Sprite1.position
    else:
        if $Sprite2.visible:
            $Sprite2.visible = false

Since the tree node is after the player node in the node tree, it will be drawn over the player.

by (20 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.