(Solved) How do I Make this kind of card hand

  • This must be a hard one to figure out because I seen a post from 2014 with no answer lol at the time it might have been hard to figure out but now I hope there might be some answers. i'm trying to figure out how to make a card hand like in this video below when player removes a card from the hand by placing it on the field and then the hand either shrinks like when a card is removed from the middle and leaves no gap. Then the cards slide over as you draw more.

    Also this hearthstone video below does the same. i'm basically looking for a way to play the cards from my hand and then have the cards in hand react like in these to videos. I'm using an array for the deck and one for the players hand if that helps to problem solve this. The cards in my hand are also animation frames from a random deck draw so i'm not sure if it's because i'm trying to place animation frames on the field and not an actually object that's giving me one of the problems but any ideas would be greatly appreciated, thanks guys.

    Subscribe to Construct videos now

    https://youtu.be/GyNq1eSHHDA

  • It’s not hard, there’s just many ways to go about it.

    I’d go for one array for the deck, and a card sprite for everything else since they are visible. To be able to differentiate between played cards and cards in the hand you could just add a Boolean instance variable inhand that with a default value of true.

    So assuming you have the deck array already populated you can deal your hand with:

    Start of layout

    Repeat 5 times

    — creat card at (0,0)

    — cars: set animation frame to deck.back

    — deck: pop from back

    Then to position the cards in a row it would be

    Global number numcards=0

    Card: is inhand

    — set numcards to card.pickedcount

    For each card ordered by card.x ascending

    — card: set position to (320+(loopindex-(numcards-1)/2)*card.width, 400)

    So then to play a card it’s as easy as setting inhand to false and moving it to where you want it. The gap will close up. Same with dealing new cards, just create it with a low x to slide in from the right. Curved is also possible, you just change how you set the position.

    Card: is inhand

    For each card ordered by card.x ascending

    — card: set position to (320, 400+500)

    — card: set angle to (loopindex-(numcards-1)/2)*5

    — card: move 400 pixels at self.angle-90 degrees

  • I'm not a big fan of arrays in C2. I repeat this almost in every post where arrays are mentioned <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I'm convinced that many things can be done much easier with objects and instance variables instead of arrays.

    Anyway, here is a demo where cards are moved like you want. I used an example from your other post, modified and simplified it (by removing arrays <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> )

    https://www.dropbox.com/s/b7qmdni2wn9ze ... .capx?dl=0

    You will need MoveTo addon to open it. It's a great behavior and I highly recommend installing it.

    If you change "order by" to spCard.cardFace in event 10, then cards in hand will be arranged by their suit and value.

  • I'm not a big fan of arrays in C2. I repeat this almost in every post where arrays are mentioned <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I'm convinced that many things can be done much easier with objects and instance variables instead of arrays.

    Anyway, here is a demo where cards are moved like you want. I used an example from your other post, modified and simplified it (by removing arrays <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> )

    https://www.dropbox.com/s/b7qmdni2wn9ze ... .capx?dl=0

    You will need MoveTo addon to open it. It's a great behavior and I highly recommend installing it.

    If you change "order by" to spCard.cardFace in event 10, then cards in hand will be arranged by their suit and value.

    For some reason my computer can't open the file because it's in a 7z file which i can't open. is there a link to that behavior that's not in a file like that?

  • I'm not a big fan of arrays in C2. I repeat this almost in every post where arrays are mentioned <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    I'm convinced that many things can be done much easier with objects and instance variables instead of arrays.

    Anyway, here is a demo where cards are moved like you want. I used an example from your other post, modified and simplified it (by removing arrays <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile"> )

    https://www.dropbox.com/s/b7qmdni2wn9ze ... .capx?dl=0

    You will need MoveTo addon to open it. It's a great behavior and I highly recommend installing it.

    If you change "order by" to spCard.cardFace in event 10, then cards in hand will be arranged by their suit and value.

    Nevermind i got it lol thanks a lot. I'm gonna look at this capx and see if this is what i need <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It’s not hard, there’s just many ways to go about it.

    I’d go for one array for the deck, and a card sprite for everything else since they are visible. To be able to differentiate between played cards and cards in the hand you could just add a Boolean instance variable inhand that with a default value of true.

    So assuming you have the deck array already populated you can deal your hand with:

    Start of layout

    Repeat 5 times

    — creat card at (0,0)

    — cars: set animation frame to deck.back

    — deck: pop from back

    Then to position the cards in a row it would be

    Global number numcards=0

    Card: is inhand

    — set numcards to card.pickedcount

    For each card ordered by card.x ascending

    — card: set position to (320+(loopindex-(numcards-1)/2)*card.width, 400)

    So then to play a card it’s as easy as setting inhand to false and moving it to where you want it. The gap will close up. Same with dealing new cards, just create it with a low x to slide in from the right. Curved is also possible, you just change how you set the position.

    Card: is inhand

    For each card ordered by card.x ascending

    — card: set position to (320, 400+500)

    — card: set angle to (loopindex-(numcards-1)/2)*5

    — card: move 400 pixels at self.angle-90 degrees

    Thank you! I'm going to combine both of your guys ideas. It should work ouot perfect!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)