"Match Pairs" game : how should I handle click on all cards?

Hello I’m trying to make a simple “match pairs” game where there is a lists of “cards” and the player have to find the corresponding pairs.

I created a factory of cards and in the main collection I have a main script that is in charge of creating the cards and shuffling / positioning them on the screen.

So far so good. Then I need the user to be able to touch/click the cards. So the first thing I did was to acquire_input_focus in my card.script. But it failed because I have more than 16 cards. I read in another thread that it was bad design (Input focus could not be acquired since the buffer is full (16) (SOLVED)), I should have only a single object responsible for the input and dispatching them to the cards.

Does this mean I have to create an object that rely on simple math to detect which card was clicked? I can do that but it feels not idiomatic.

I’d love some suggestion from power users, it’s my first non-tutorial game!

I tried to use https://github.com/britzl/defold-input/blob/master/in/cursor.md, but same issue (buffer is full).
I also tried https://github.com/britzl/publicexamples/blob/master/examples/click_game_object/click_game_object/goput.lua but since my cards come from a factory I wasn’t able to get their sprite (I only have the gameobjects’ ids)

I uploaded the code if that helps: https://gitlab.com/bchamagne/jbc-memory

That is what I would do. If the cards are on a grid there is little point in doing this more complicated than necessary.

2 Likes

Thank you for the quick reply!
I’ll do it this way then, cheers!

Exactly! There’s no need to overcomplicate things!

1 Like