How do I find the rect_position of a instanced node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By O_Chernobas

I’m making a card game, that requires the player to pick a card, confirm, and change the position. I was using the get_viewport().get_mouse_position() to find the mouse position, and comparing it to the card position, if it was >= the card position, and <= the card size, this card was selected, but I don’t know how to discover the card position at the scene, I tried to use the rect_position property, but isn’t working.

Does someone here know how to discover if the mouse was clicked inside the card area?

Main Scene script:

extends Control

onready var BlackCardText = $GamePlace/BlackCard/RichTextLabel
onready var BlackCardPick = $GamePlace/BlackCard/Escolha/RichTextLabel
onready var Hand = $GamePlace/Hand/GridContainer
onready var WhiteCard = preload("res://WhiteCard.tscn")

var BlackListDictionaire = {
	1:["se", 1],
	2:["mata", 1],
	3:["barreto", 1],
	4:["veras", 2],
	5:["pprt", 2],
var WhiteList = ["se","mata","barreto","veras","pprt",]
var rng =

func _ready():

func _input(event):
	if Input.is_action_just_pressed("testblack"):
	if Input.is_action_just_pressed("testwhite"):

func set_black_card():
	BlackCardText.text = BlackListDictionaire[rng.randi_range(1,5)][0]
	BlackCardPick.text = str("Escolha ", str(BlackListDictionaire[rng.randi_range(1,5)][1]))

func set_hand(value):
	for i in range(value):
		var Whitecard = WhiteCard.instance()

Card scene script:

extends Control

func set_text(text):
	$RichTextLabel.text = text

func _input(event):
#	print(self.rect_position)
	if Input.is_action_just_pressed("mouse1"):
		var mouse_position = get_viewport().get_mouse_position()
		if mouse_position.x >= self.get_position().x && mouse_position.x <= (self.get_position().x + self.rect_size.x):
			if mouse_position.y >= self.get_position().y && mouse_position.y <= (self.get_position().y + self.rect_size.y):

Main Scene:
Card Scene:

:bust_in_silhouette: Reply From: vnmk8

You can use Area2D node built in signals called mouse_entered() and mouse_exited() to do that.

I tried to use the area 2d as a child of my control card node, but it seems that is not responding

O_Chernobas | 2021-07-31 03:48

responding to what?

vnmk8 | 2021-07-31 03:50

I pass the mouse trough the area 2d, but the signal is not activated

O_Chernobas | 2021-07-31 03:54

you can see if you hover over the signal that it requires the area node pickable option active and at least one collision layer bit to be set

vnmk8 | 2021-07-31 03:56

I have the collision layer, but I need to activate this pickable option ?

O_Chernobas | 2021-07-31 03:59

yes you can see in the screenshot I took
Imgur: The magic of the Internet

vnmk8 | 2021-07-31 04:04

so, i need to write a function inside the area2d func set_pickable(true) ?

O_Chernobas | 2021-07-31 04:08

you can do it in the inspector under the collision layers there’s the option for Pickable
Imgur: The magic of the Internet

vnmk8 | 2021-07-31 04:10

It’s set true, but isn’t working, maybe is because i’m using an area2d inside of a control node ?

O_Chernobas | 2021-07-31 04:15