0 votes

I am making a Point & Click game, and I am trying to show a sprite when an area2D is clicked (outside of sprite). Then I need it to disappear when another click is registered. Can anyone help me?

Godot version 3.4
in Engine by (14 points)

1 Answer

0 votes

Something along these lines should do the trick:

extends Area2D

onready var the_sprite = get_node("path/to/sprite")

func _ready() -> void:
    input_pickable = true
    self.connect("input_event", self, "_on_Area2D_input_event")

func _on_Area2D_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
    if event.is_action_pressed("mouseleft"): # set this up in project settings
        the_sprite.visible = not the_sprite.visible
by (3,707 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 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 webmaster@godotengine.org with your username.