Hi, this is kind of like a Part 2 of my previous question. I have 5 rectangles in a table all positioned at the center of the screen. The problem is all 5 rectangles are in the exact same spot. How can I have one centered, and then have the other four on either side of it? Kind of like this picture. (notice the arrow) Feel free to ask for any code. Thanks in advance!
I don’t understand your problem. If they’re all in the same spot, can’t you just change x and y-coords to solve your problem and just keep them with respect to display.contentCenterX?
I could change them individually, but I am just wondering if there was a different way. I have been having problems where the rectangles are not where they are supposed to be in different devices.
Never mind, I got it!
In case anyone has a similar problem: all I did was set the id for each rectangle to be -3 + i (which is their place in the table, in this case a max of 5), and then I set their x-coordinate to be the center of the screen plus the id multiplied by 75.
The end result:
A responsive set of 5 rectangles next to each other that will always appear in the center of the screen.
for i = 1, 5 do unitBox = display.newRect(i \* 75, 100, 50, 50) unitBox.id = -3 + i unitSet[i] = unitBox unitSet[i].x = centerX + unitBox.id \* 75 end
It would be better to place your 5 boxes in a display group and then position the display group at centerX. You can then animate the display group, show and hide it, etc and the embedded boxes will all change as one.
I don’t understand your problem. If they’re all in the same spot, can’t you just change x and y-coords to solve your problem and just keep them with respect to display.contentCenterX?
I could change them individually, but I am just wondering if there was a different way. I have been having problems where the rectangles are not where they are supposed to be in different devices.
Never mind, I got it!
In case anyone has a similar problem: all I did was set the id for each rectangle to be -3 + i (which is their place in the table, in this case a max of 5), and then I set their x-coordinate to be the center of the screen plus the id multiplied by 75.
The end result:
A responsive set of 5 rectangles next to each other that will always appear in the center of the screen.
for i = 1, 5 do unitBox = display.newRect(i \* 75, 100, 50, 50) unitBox.id = -3 + i unitSet[i] = unitBox unitSet[i].x = centerX + unitBox.id \* 75 end
It would be better to place your 5 boxes in a display group and then position the display group at centerX. You can then animate the display group, show and hide it, etc and the embedded boxes will all change as one.