I have a GUI that’s meant to represent a pile of rocks. When a player clicks and drags a rock, a new rock is supposed to spawn at the bottom of the pile.
Creating new GUI objects (ImageLabel, in this case) places the ImageLabel on top of any existing frames, instead of at the bottom. I’ve tried to work around this by creating a new piece and shifting the positions of all the ImageLabel to the next one down. The frames are placed in the Rocks array in the order they were created, such that the top of the pile should be represented by the end of the array, and the bottom of the pile should be represented by the start of the array.
This is the code I use to shift the positions around in an attempt to make the rocks shift around seamlessly, but it does not work properly:
local i,k = #Rocks,#Rocks-1
while k > 0 do
if Rocks[i].IsDragging then
i = i-1
end
if Rocks[k].IsDragging then
k = k-1
end
if k <= 0 then
break
end
Rocks[i].StartPosition = Rocks[k].StartPosition
Rocks[i].Decal.Position = Rocks[k].Decal.Position
i = i-1
k = k-1
end
Rocks[1].Decal.Position = GetNewPosition()
Rocks[1].StartPosition = Rocks[1].Decal.Position
There is flickering among the labels that are near the top of the pile, and some of them get re-ordered unexpectedly. You can see this happening here:
Is there a better way to make a system to add GUI objects to the bottom of a pile?