How do I...Arrange/Distribute Sprites Evenly?

  • Hey all, I have a quick question. I'm trying to make a card game that will have a hand of cards with between 0 and...let's say 30 cards. The hands would probably average between 4 and 6 cards in it at any given time. I am familiar with a wonderful little tool in Adobe Illustrator that allows one to select several objects and arrange them evenly in an area, much like this:

    I start with five randomly-placed squares:

    And then I use the "Horizontal Align Center" command:

    And then i use the "Vertical Distribute Center" command:

    This last step is what I'm after. I would love to have events that count the number of cards in hand and vertically distribute them so that they are evenly spaced and easy to read. Is there an event action that can make this happen? Thanks for your help!

  • Hey Methuselah!

    This may be not exactly what you want, but I had this capx with card game related functions. One of them organizes the player's hand. It might help you to make your own. ... .capx?dl=1

    Hope this helps. Cheers!

  • To arrange the sprites like in your example you can do this:

    for each sprite

    --- set position to (lerp(100, 300, loopindex/(Sprite.count-1)), 400)

    100 if the leftmost x and 300 is the rightmost. 400 is the y.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Also, I got my "horizontal" and "vertical" backwards in my OP, so oops.

    But thank you both! R0J0hound, that is exactly the thing I was looking for. brunopalermo, your example is totally what I want to have in my game. Thanks again!

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