Hi! I’m a bit new to programming (and game design as a whole) and I have something for a game I’m working on that I have no idea how to approach. What I’m trying to achieve is a program that, when given several frames of random size and position, can create a parent frame that encapsulates all of them.
I’m not completely sure the best way to describe this problem so I’ll give a picture here.
As you can see by this terribly scuffed beautiful diagram I have a series of random frames, and I’m trying to create a parent frame that has a 10 pixel padding around them all. Ideally, this system could also update itself when a new frame is added or removed, or an existing frame moves or changes its’ dimensions.
Honestly, I really have no idea how to approach this problem. My first intuition is to get the size and position of a random frame, create the parent frame, and then compare the dimensions and the positions of all the other frames and do some equations to find the proper size of the parent frame. But even laying it out like that, I still am clueless where to start. Does anyone have any ideas? Thank you!
Loop through all frames you wish to encompass with a larger frame and:
Use GuiBase2d.AbsolutePosition to get the centerpoint of each frame and find where they begin and end by adding/subtracting the X and Y size divided by 2 to the centerpoint.
Store and replace the maximum and minimum values for X and Y locations.
Finally, Create your new frame at the position in the middle of these values, with the size of the distance between these values, plus whatever padding you want.