HTML5 deck of cards management – 1024×1024 texture version

If you like the HTML5 deck of cards management and tried to run it on your mobile device, probably you weren’t able to display cards properly.

This is not a bug in the code, it’s just the original 4342×1760 image with all cards is too big for your mobile device to handle.

While searching around the web you can see a 2048×2048 is safe enough for mobile devices, I decided to use 1024×1024 textures to avoid any kind of problem.

So basically I had to split this big picture


into small slices smaller than 1024×1024. Photoshop has a lot of ways to slice images, and this is what I ended up with:

Now, the only thing we have to do is to load the proper texture according to card value. Phaser Sprite class features loadTexture method which allows us to change texture on the fly.

And this is the result, exactly the same as before:

A deck of cards is shuffled and the first card is drawn on the table. Then you can swipe up to make next card appear above current card or swipe down to make next card appear below current card. Then next card takes the place of the current card which leaves the stage, and you can swipe to call the third card, and so on.

And this time it will work on every mobile device. Test it at this link.

And this is the update source code, still to be commented but fully working:

Less than 100 lines for a deck of card management with tweens and swipe detection. Thanks to the power of Phaser.

Next time I will turn it into a small game, meanwhile download the source code.