Attention | Topic was automatically imported from the old Question2Answer platform. | |
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 = RandomNumberGenerator.new()
func _ready():
set_black_card()
set_hand(3)
func _input(event):
if Input.is_action_just_pressed("testblack"):
set_black_card()
if Input.is_action_just_pressed("testwhite"):
set_hand(1)
func set_black_card():
rng.randomize()
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):
rng.randomize()
for i in range(value):
var Whitecard = WhiteCard.instance()
Hand.add_child(Whitecard)
Whitecard.set_text(WhiteList[rng.randi_range(0,4)])
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):
print("OI")
Main Scene: http://i.prntscr.com/n-NlcB2ZQV24YnbuKOjhuQ.png
Card Scene: http://i.prntscr.com/TRY66Rv6SaG6fSo6Is2JvQ.png