0 votes

Hello, I wrote this code ..... which makes clicking on any part of the scene to hide a sprite ...

extends Node2D

func _input(event):
    if(event is InputEventMouseButton):
        if(event.pressed):
            $Sprite.hide()

This code is from another scene ...... and it says that clicking a button instantiates the scene..

extends Node2D


var carta = load("res://Scenas/Carta.tscn")


func open_scene():
    var newcarta = carta.instance()
    add_child(newcarta)
    newcarta.global_position = global_position + Vector2(600,400)

func _on_boton_pressed():
    open_scene()

EVERYTHING WORKS WELL ..... THE ONLY BAD THING IS THAT WHEN THE SCENE IS INSTANCED ........ THE IMAGE OF THE INSTANCE SCENE THAT SHOULD BE HIDDEN AFTER CLICKING ... IS HIDDEN IMMEDIATELY .... . AS IF YOU HAD BEEN CLICKED ... BUT I DIDN'T TAKE THAT ACTION...

Maybe they know why that happens ......

asked May 2 in Projects by Yamz (73 points)

So you have a Main-scene looking like this:

- Node2D (with the second script attached to it)
  - Button (with its pressed-signal connected to _on_boton_pressed)

And a Carta-scene looking like this:

- Node2D (with the first script attached to it)
  - Sprite

Correct? And clicking the Button spawns an instance of the Carta-scene (have you made sure this really happens?) but the Sprite never becomes visible? If so, I cannot reproduce your issue, works fine. Maybe you can provide an example project?

1 Answer

0 votes

upgrade ...
I think what happens is the scene is instantiated so fast that it also detects the click that was made to instantiate it ..... how can I fix that

answered May 2 by Yamz (73 points)

I wouldn't recommend you answer your own questions just for an "update", as this decreases it's visibility because it's no longer marked as "unanswered". You can edit your question by clicking on the three little dots in the bottom right corner of your question and selecting "Edit".

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.