my card scene tree

I want to make a card game where player can stack cards on top of each other (like Solitaire or Stacklands). I have a control node as the root node and Sprite2D as the child node. The card already has dragging mechanic but I'm not sure how to create the stacking mechanic. I suppose the first step is to make the card overlap detected but I don't know how to do it with control node

thank you in advance!

1 Reply 1

You'll need to connect to the signal mouse_entered() and also check if a card is being dragged at the same time. There are a lot of different ways to do this, but one idea:

class_name Card extends Control

static var current_card: Card = null

func _ready() -> void:
  mouse_entered.connect(_on_mouse_entered)
  

func _on_mouse_entered() -> void:
  if current_card and current_card != self:
    print("dragged %s into card %s!" % [current_card.get_path(), get_path()])

You'll need to set Card.current_card = <some card> when you start dragging it, and clear that by setting it to null when you're not dragging it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.