How Do I Insert AnimName into Array Loop?

  • I am experimenting with the card shuffling code presented in the following tutorial: https://www.scirra.com/tutorials/469/im ... -algorithm.

    I have set up my card deck as a sprite called obj_HeroDeck. This sprite has 10 separate Animations, called, "ID_H01_CardName," "ID_H02_CardName," "ID_H03_CardName," etc.

    Each of these animations is a specific sprite of a playing card within the deck.

    As the array is randomized, how do I insert the names of the different animations into the array loop so that the animation names can be called for use in a function?

  • Another question:

    Would it be better to set up the card deck as a sprite with its cards imported as Animation Frames, instead?

  • Hello,

    Would it be better to set up the card deck as a sprite with its cards imported as Animation Frames, instead?

    It does not really matter. If you want to animate your cards at some point, the solution with different animations is better. If you don't need animations, then using frames might be a tad easier.

    The while loop and there especially how the i is set up and how it uses global variables make me cringe a bit. So I use code with a for loop instead that's less error prone and imo easier to grasp, because everything is at one place in my example (also it is a function as it should be, since you want the shuffling to be reusable):

    https://copy.com/QXGb4317KtymzkQ9

    What should interest you the most is probably the event that creates the cards and sets the animations.

    For example you could write (with your names mentioned up top):

    "ID_H"&zeropad(deck.curvalue, 2)&"_CardName"

    Problem: if you want to fill in the CardName with an actual card name, this won't work anymore.

    In that case you will need a dictionary or another array, where you store the name, which then you can let C2 read, when it's time to set the animation.

    I'm not sure what kind of properties your cards will end up with. There is also the possibility to just fill an array with all the information, each card has its own x, and then y = 0 would be card name, y = 1 would be animation name and so on. You can read in stuff like this even from a csv file. Just be aware that importing the data from csv will import numbers as string, if you don't explicitly convert them upon adding them to the array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • mindfaQ, thank you very much for the reply. I will study your .capx file, and consider what you wrote above.

  • Problem: Using the method suggested, I am getting duplicates of cards from randomization. I need non-duplicating results.

    To create one of the two draw decks, I am now trying the following:

    Importing all of the playing cards into the "Draw Deck" sprite object as Animation Frames (instead of as separate animations).

    The actual playing cards will have different images (as opposed to the numbered cards I am using for testing the shuffling). And, they need to have UIDs.

    I assume I have to use an array to load the animation frame images into before the cards are shuffled.

    Question: How do I import the animation frame images into an array (called, array_HeroesDeck) and then randomize the position of the animation frames within the deck array so they can then be drawn in order during the course of the game?

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