Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Auto-Fitting ImageLabels to Frame boundaries?

Asked by 9 years ago

Hi everyone, I'm starting development of a card game, and I have used the following code in the command bar to fit 22 cards (ImageLabels, with offset sizes of 85 by 120) into the boundaries of a Frame, keeping a constant spacing between the cards:

for i,v in pairs(game.Selection:Get()) do v.Position = UDim2.new(v.Position.X.Scale,v.Position.X.Offset,(0+(0.0355*(i-1))),0) end

Here is an example of what Player 1's hand looks when using the following code, and here is an example of what I'm trying to achieve.

Now, I want to be able to keep fitting more cards into the Frame, as opposed to making a cap of 22 cards in a hand (so that the cards in the hand don't go outside the screen), but I have no idea how I would do this.

I am currently creating a card handling script to handle the loss/gain of cards of a player, and I am thinking of using the ChildAdded and ChildRemoved events to try and keep sorting the cards as new cards come in or as cards are played.

My question(s):

So I have multiple questions to ask, so I'll put them in a list:

  1. How would I be able to position all the cards so that all the cards will fit into a Frame, keeping a constant spacing between them?
  2. What is the best way to avoid duplicate cards? (I am thinking of generating an identifier value for all of the cards and compare them to a identifier value in a table consisting of all the player's cards.)

Sorry if what I'm asking is too hard to understand, I'm just beginning to develop the game mechanics as I type up this question.

0
1. You might be able to just use the scale, as that'll automatically adjust it to the size of the frame. 2.I suggest setting up a multidimensional array for your purposes here, and then just running a for loop for identification of cards. Vathriel 510 — 9y
0
I am using the scale, I just need a way to change the space of the cards depending on the amount of cards in the hand. I can fit 22 cards into the frame already with the code provided above but I am trying to find a way to fit more cards in, as the game I'm creating could easily take the player over 22 cards in their hand if they've got really bad luck. Spongocardo 1991 — 9y
1
Scale the images do and to get the perfect size do 1/#OfUnoCards DragonSkyye 517 — 9y
0
That was an idea I had, but I didn't know if it would work. I'll try it now. Spongocardo 1991 — 9y
0
Okay, after messing around with the command bar for half an hour, I've finally got a working sorting formula that changes with the size of the hand, thanks colt. Now I'm going to try and find a way to avoid duplicate cards when the script is trying to create the cards for the player's hand. Spongocardo 1991 — 9y

Answer this question