I've never written card games before and am currently coding up a simple card game, I have a deck of cards and they need to be shuffled (done) and then draw from the top deck into a tableau (centre of table) from which the user(s) can pick from.

The only issue is I'm not sure how I can figure out where the cards drawn from the top deck go to.

Let's say the draw deck is drawn at 100,100.

Let's say the tableau starts at 200,200 and can have 6 cards in them.

How do I know where the cards are going to appear on screen within the tableau?

My current thoughts are that we fill the tableau "empty" card objects at set X/Y co-ordinates so that I know without having to do too much programming where the cards should go to.

But I'm not sure if this is the best way to do it because of screen sizes, etc.

ie: Tableau. A card width is 50, and the distance between them is 20

> Card slot #1 = 200,200 (State: Empty)
> Card slot #2 = 270,200 (State: Empty) 
> Card slot #3 = 340,200 (State: Empty) 

So the first card drawn would animate from 100,100 to 200,200 and change it's state to Filled The second to 270,200, changing its state The third to 340,200, changing its state And so on..

But I'm still unsure if using hard number co-ordinates is really the best way forward, especially if the screen sizes change; or even if there's a better way to animate cards from a draw pile to a tableau.

My question therefore is -- how do I make the computer know where to put cards drawn from a deck of cards to a tableau?

Many thanks


1 Answer 1


Method I am using is adding a scalar in my camera's view matrix. This scalar is the comparison between the device's screen size and the size I made the game for. For this to work you do need to be able to access your device's screen size in your code.

Even in games with no screen movement I have a camera running in the background. Usually a basic camera (C# XNA example) for games without screen movement. Then I add a little method which would look like the following:

void AdjustScreenSizeScalar(float screenSizeX, float screenSizeY)
    screenSizeScalarX = screenSizeX / /* Your expected screen size X here */
    screenSizeScalarY = screenSizeY / /* Your expected screen size Y here */

And for creating your view scalar you can do the following:

//scalar = your normal scale stuff
viewScalarX = scalarX * screenSizeScalarX;
viewScalarY = scalarY * screenSizeScalarY;

After that just make sure that all your objects use the view of the camera. How to do that depends on your code. But once you do that you can use your normal positioning stuff and the game will adjust itself when the screen size is different than the 'expected' size.

Hope this helps!

  • \$\begingroup\$ This does help, but do you still suggest filling the Tableau with empty Card parameters? \$\endgroup\$
    – zardon
    Commented Jun 23, 2014 at 15:00
  • \$\begingroup\$ Yes, I would do so. It gives you a quick check which spot is available and which is not. Besides it contains the position for future cards. \$\endgroup\$
    – RdeGier
    Commented Jun 23, 2014 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .