0 votes

Hi, I'm a web developer with experience in JavaScript (angular, react and node), Java and C#, so not a complete noob programming wise, however, I am a complete noob when it comes to game development. But I'm very eager to learn more. As my very first game I decided to make a little card game.
One of the first things I wanted to try was to make hand of cards, something like this: enter image description here So to get started I just spawned a couple of sprites wit areas and shapes that looks something like this:

Area2D (with script attached)

I can drag and snap images in place, no problem there. However my problem arises when 2 images overlap eachother. From then on, whenever I drag one around, both get moved around. My issue is pretty similar as the one posted here. where they say to "use the space2d to query" but I can't seem to find any further documentation on it, so I don't really know how to go on from here.

This is what my input+event code looks like:

func _input_event(viewport, event, shape_idx):
    if event.type == InputEvent.MOUSE_MOTION or event.type == InputEvent.SCREEN_DRAG :
        event = make_input_local(event)

Any pointers are greatly appreciated!

in Engine by (15 points)

2 Answers

0 votes
Best answer

I think you're better off using UI based nodes and wiring up its inputevent, mouseenter and mouse_exit

signals than what you're currently using.

    |_ TextureFrame

Wire up these signals on the Control node



Check out the example on git

by (122 points)
selected by

Thank you very much for the example! This works much better indeed, also, the tracking on a touch screen feels smoother than with the area/collisionShape combo.

One more question though: When 2 cards overlap eachother, it's possible that the bottom card get's selected on a click. Do you know of a way to always get the top (visible) card in that situation?

0 votes


Can't believe it. :D Was looking for a card game to include in my project, posted a question for that, and I just stumbled on yours...

My project is Onyris (first time I read about your project), an rpg/adventure game of survival/race/socials set in dream world, and I need a card game as a chalenge to win a special card, of the world game. It happens in the library, against the librarian.
Here is the project, at its begining, in progress: http://dl.free.fr/q6ds4MvYQ

Would you be willing to be a part of it, just leting me using your scripts and mechanics, or more as it seems to fit perfectly in my universe?

by (321 points)
edited by
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.