Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Yamz |
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 …
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?
njamster | 2020-05-02 15:01