Implementing a Card Game in Defold

Hey, I’m learning Defold to try to design a card game. I have a solid background in both tabletop games and software engineering but I’m totally new to game development, so I wanted to ask a couple questions to make sure I’m understanding the engine correctly.

My biggest question right now is what the best way to implement cards is. As I understand things, a card game object needs a sprite for art and a script that defines its properties (like power and toughness), how the user can interact with the card (eg. playing it), and the card’s effects. I can use modules for properties that a lot of cards share (like the drag and drop logic or common effects), but it seems to me like each card will ultimately need an unique script. And engine-level stuff like the collision objects will need to be manually set for each card.

The best solution I can think of right now is to have a game object for each card in my game, some controller that tracks the players’ decks and hands, and I’m guessing there’s some way that I can generate the game objects I need at runtime by naming the cards and game object addresses intelligently.

I’m wondering if there’s maybe something better I can do with a factory. Like maybe I could store the references to the sprites and scripts for each card in a json file and pass them in as factory parameters? That particular solution doesn’t really sound better than having an object for each card though.

Sorry if these thoughts aren’t super clear, I’m still very new to game engines. Thanks in advance for any help!

You are still able to use an object for each card with a visual field referencing to the game object id

What I would do is have a cards.json which has the id of each card and any other information, then have a card.go which is used in a card factory. When creating a new card via the factory it would pass the card id to card.go and via that you can set the correct sprite and any other data. For example your card sprite names could just be the card id and the other data is obtainable by looking up the card id from the json data (which would be loaded in memory at the start).

Thanks! I’ll think some more about how to do that. It sounds like my instinct that I’d need to use an object for each card was wrong though.