0 votes

I am making a simple card game in 2D and I have created my Sprites dynamically.

How can I attach a click event on them? I've seen that you can use Control or Area2D/RigitBody2D but is there something simpler for that?

in Engine by (69 points)

Have you seen the TextureButton node? You can attach a texture to it for various states (normal, pressed, hover, clicked, etc.). It also has the "pressed" signal that you can wire into your custom logic.

As @2D||!2D said, TextureButton is simple clickable sprite.

No, I haven't seen it, thanks for the tip. I am using gdscript for the card spawn, how does the wiring occur there?

Check out this discussion and this discussion. They should give you the information you need.

You can extend the TextureButton class. Inside this class, in the _ready() function, you can connect its "pressed" signal to a function in a card manager/etc and pass the card's name'id/etc to the the function in the card manager and treat it how you need to. That help at all?

Please log in or register to answer this question.

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 Frequently asked questions and 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.