Playing cards for B4A?

karmacomposer

Member
Licensed User
Longtime User
Amazing. I will be needing the EXACT same thing for a project I will be doing shortly.

I am guessing you use an image control to show the card and when you 'flip' it, you just assign another image to that same image control.

The rest is animation done through math or animation controls, I guess.

Mike
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
http://www.b4x.com/forum/code-samples-tips/1648-card-images.html

and

http://www.b4x.com/forum/questions-help-needed/6181-dll-questions.html

The card images are packed in data files for use with Basic4ppc BinaryFile.RetrieveImage. I can't remember what format the actual images are, probably bmp or jpeg but unpacking them should be easy. The file format is an 8 byte (64 bit) Int64 byte count then the file image as a byte sequence, then another Int64 byte count and the next file and so on. The Int64 will be little-endian and depending on how you read it may need transposition to big-endian under Android
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

I had looked at the links above before making the original post but when I searched HelpViewer for RetrieveImage and got no hits and downloaded the CardDemo app and couldn't make sense of it, I gave up.

The only thing I know about Big and Little Endians is that I open my boiled eggs in the middle (obscure Gulliver's Travels reference), so those images may as well be locked in a safe as in an a file with no code for getting them out.

If someone can tell me how to extract the card faces (and back), I'll upload the B4A source code for my old CardShark Spades and CardShark Hearts games when I get them converted.
 
Upvote 0

Bob Katayama

Member
Licensed User
Longtime User
If someone can tell me how to extract the card faces (and back), I'll upload the B4A source code for my old CardShark Spades and CardShark Hearts games when I get them converted.

What I have done with other Basic languages in the past is use an array that represents the images.

A$(0) = "backimage.bmp"
A$(1) = "AceofSpades.bmp"
A$(2) = "2ofSpades.bmp"
ETC. . . up to 53 cards or 54 including a joker.

You can also use image names lke C1.bmp to C54.bmp

The other option is to use a 2D array like A$(3,12) which breaks the cards into the different suites if that is advantages for the card games functionality.
A$(X,12) X represents the different suite (0 to 3) and the 12 are the cards from ACE to KING (0 to 12). The back card can then be just an independant Array like B$ = "Backimage.bmp" since all cards use the same image.

Does this help some what? Sorry it is not coded specifically to Basic4Android but I am just getting my feet wet with this version of Basic.

Bob
 
Upvote 0

dlfallen

Active Member
Licensed User
Longtime User
The attached demo program includes a full deck of cards. Although the demo just shows the faces of the 52 cards, if you look in the files you will see various backs and jokers.

The images are 71 x 96 png files. As you can see, I added ImageViews and loaded the images as needed.
 
Upvote 0

etLux

Member
Licensed User
Longtime User

Thank you, dlfallen!

Do you mind if we use these in some of our own efforts?

I have a neat little app in mind that these would be
perfect for.

All the best,



David
-----
David Sosnowski
The Music of David Sosnowski
 
Upvote 0

Bob Katayama

Member
Licensed User
Longtime User

Thanks for this.

Are you OK with me modifying your code and uploading a new version?

Bob
 
Upvote 0

dlfallen

Active Member
Licensed User
Longtime User
As far as the code goes, do anything you like. I just slapped it together quickly to give an idea of how to use the image files.

You can also do what you wish with the png files. I didn't create them and have no license over them. I think I originally got them here:
Playing Cards
In any event, I agree with that site that the front images are in the public domain. Can't say what the status is of the jokers or the backs - I picked them up in various places.

If you want, there are a lot of decks available under GPL or GNU licenses. Check out this web site: Free Card Decks & images to download: Free Tarot cards and Playing cards for download
which has many, many decks available. I downloaded the "Huge" collection which had square cards, round cards oval cards, small cards, French cards, German cards, etc. Many of the decks sport great old-fashion court cards. All apparantly are usable under GPL or GNU.

For me, I may port my Let It Ride program over to Android (see the B4PPC forum) but probably will not do much else. I look forward to seeing the programs you guys are writing!
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

This is getting bizarre - this is the third app I've gotten from this forum which will not install. Below is a screen shot of the error(s).

However, this time I decided to try to isolate the problem, so I started a new app, cut-and-pasted the code into the IDE, copied the Files folder over, and ran the code, first without the "Dim ImageView..." and "ImageView1.Bitmap=...", and it loaded okay.

Then I added back the "Dim..." statements and it loaded okay. Then I added the rest of the code and the whole program ran okay.

So I went back to the Cards.b4a and ran it and it gave me the same errors as before:



I've uploaded a copy of my files here.
 
Upvote 0

etLux

Member
Licensed User
Longtime User
Gee, that all looks familiar... lol.

I can almost never get an app to load in the emulator.
The emulator, I use just for design... and really not even
that much anymore, since I generally hand-code layout.

For testing, I hook straight to my DroidX -- which works
great.

I'm not sure what the deal is with the emulator being
so uncooperative -- maybe one out of ten shots I can
get it to load, even if I extend the time-out. I'm running
a squeaky-clean, well kept Win7/x64 with 12G RAM and
a hot i7 processor... so I don't think it's lack of resources...

If anyone has any insight on what this is that bogs the
emulator I'd love to hear it -- though really, developing
straight to the Droid X works gangbusters for me...
very quick loading.

Best,



David
------
David Sosnowski
The Music of David Sosnowski
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
When I go straight to my device (an Archos 70-250G), I get this error:

ZipAlign file. 0.03
Installing file to device. Error
pkg: /data/local/tmp/Cards.apk
Failure [INSTALL_FAILED_DEXOPT]

What I don't understand is why it worked when I copied all the code, layout, png files, etc., over to a new project and ran it.

Anway, other than curiosity, I guess it doesn't matter since the card display is working in the new project.
 
Upvote 0

dlfallen

Active Member
Licensed User
Longtime User
I'm no expert here (just learning myself) so Erel, Andrew, Klaus, or another expert may correct me. But it seems you are trying to install the apk file. I did not sign that file (or more accurately, it is signed with the default debug signature) so that may be why you can't install it directly. If you unzip Cards.zip with the defaut folders, start B4A, and through the Menu, choose Open Source, browse to Cards.b4a and select it, the source code will be loaded. When you then run the program it will compile and be loaded onto whatever device your are using and should run just fine from then on.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User

Nope, I wasn't trying to install the apk. As I said, I was running Cards.b4a and got the errors shown, then I pasted the code from Cards.b4a into a new project/b4a file and it loaded and ran fine, then I went back to Cards.b4a and it bombed out again.

As far as that goes, is it even *possible* to install an apk file into an emulator? I've never tried that. Wouldn't even know how.

Anyhow, the real mystery is why/how Cards.b4a would not compile when the same code and files copied over compile and ran fine. I figure something in the Object folders must be different, but I couldn't make a lot of sense out of that stuff, which is why I uploaded my b4a files, in case someone else could spot something.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
You can try cleaning the project by choosing Tools - Clean Project. It might help.

More strangeness --

I loaded Cards.b4a and clicked on Clean Project, then compiled it and it worked on both the device and the emulator.

So I loaded Hubble.b4a, which is the first one that caused my A70 to reboot. I was planning on clicking Clean Project for it, but I compiled it first (wish I had run Cards before Clean Project) and Hubble worked.

Then I loaded TTS.b4a, which also had previously caused a reboot, and it worked without doing a Clean Project, so now I'm questioning if Clean Project actually caused Cards to work or if something else is going on.

I don't turn off my computer at night, so the only thing different from yesterday is that last night I turned off the A70 and unplugged it from power (but not from the USB) and today plugged it back and and turned it back on, but while that may have cleared out the A70, it doesn't explain why the apps suddenly started working on the emulator.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…