Just to be clear, I am discussing writing a 2D card game based on a board game and I do not have permission to write it or any affiliation with the board game designers or manufacturers. I don’t intend to share or distribute this game to anyone ever. With that disclaimer out there, I’ll now discuss the issues that I’m encountering while trying to learn about 2D game development with Unity.

Unity is a development tool, API, and a bunch of other things that all work together to let a programmer create 2D and 3D rendering software. I wrote a simple 3D Lunar Lander game a while back and now I’m trying to write a simple 2D card game. I think that I might actually want to finish this card game. But if I don’t, I’ll still have fun learning how to do it.


Unfair Screen Layout Idea

The first thing I did after creating a Unity project and selecting the 2D development option, was to create a playing card sprite in the scene. I used an image of a card from the game and “cut a hole in it” using PNG transparency to see if it worked as I expected. I will eventually use this to round the corners of the cards.


Test Card Image

The second thing I did was create a child class of MonoBehaviour called CardMover that I could add to my sprite as a component. And excuse me if I use some incorrect terminology; I think that I actually have a sprite as a component of the card game object and it, itself, is not the sprite. Anyhow, The CardMover class has an Update() function like all classes derived from MonoBehaviour and it is amazingly simple to use that to move the card without the card class knowing that he CardMover class even exists (yet). The CardMover class has some function to implement the move operation. Right now, the card is moved from a fixed screen location to another fixed screen location. it also is shrunk to 50% its original size and rotated 15 degrees clockwise. This was a test to see how card sliding looks on the screen.

Before I go on, I want to mention my inspiration for this project. The Though the Ages game app is one of the highest quality games that I’ve played on both Android and iOS. It has a great, and humorous, tutorial and the user interface look and feel is perfect for the game. They did an amazing job of taking a card-based board game and making it into an app.


Through the Ages


Through the Ages – Cards in the User Interface

Right now, I have a few cards on the screen that are all identical looking. They all use the same sprite and CardMover components and clicking or tapping a card causes it to jump to the start location and slide to the new position on the screen, changing scale and rotation as it goes.


My Game So Far

I am also working on a singleton/static class as a game manager. The state of the overall game needs to be tracked in some global way. But for now, I’m using this class as a screen organizer. When a card is positioned on the screen, it will not be given X,Y coordinates, it will be given some information about the virtual location of the card. Whenever the card is moved, it will use this table location “ID” to move to the correct X,Y coordinates for the size and shape of the screen. I am already getting into uncharted territory here because I have no idea how others manage this type of information. I want the game to move and scale the entire game layout to fit the screen even if the screen size is being changed interactively by the user. That will make it run fairly well on a PC. For iOS and Android, I could probably just compute this position information once when the app first starts up. But it seems to be easy to handle screen size changes and update the cards and other UI elements when needed.

With the singleton game object idea decided on, for now, the only thing left to work on right now is the sprite management. Creating 300 or more sprites for every card using the Unity editor seems like a terrible idea. The best option that I can find described online is to create a game object for a card and”give” it all of the components it needs to work as any card in the game. I will then create a prefab in Unity and at runtime, the game will create an instance of the prefab and then select the image for the card from somewhere. I don’t want this to be slow so I may have some sort of single image for the cards at medium resolution and load the card image into memory so it’s there the entire game. This will work well since I can load just the card images for the decks being used for the current game. I’m not sure about cards that have specific features (almost every card). Maybe one class with a function for each card feature. or a separate class per deck so I can add decks to the game one at a time and not be changing working code too much. This is all new for me.