Arranging display hierarcy

I have 5 objects and they are constantly moving around and I want arrange the display hierarchy according to y cord. The largest y cord will display in front and smallest at the back. Anyone can help? [import]uid: 40786 topic_id: 24464 reply_id: 324464[/import]

Anyone? [import]uid: 40786 topic_id: 24464 reply_id: 99191[/import]

First, you’d need to order them from lowest to highest y coord (or highest to lowest). Next, object:toFront(); them in reverse order. For example:

[lua]function orderDisplay()
local lowest, low, middle, high, highest;

–objects are named o1, o2, o3, o4, and o5

–Find the highest and lowest
highest = math.max(o1.y, o2.y, o3.y, o4.y, o5.y);
lowest = math.min(o1.y, o2.y, o3.y, o4.y, o5.y);

–Determine which was the lowest and then find the
–next lowest.
if(o1.y == lowest)then
low = math.min(o2.y, o3.y, o4.y, o5.y);
elseif(o2.y == lowest)then
low = math.min(o1.y, o3.y, o4.y, o5.y);
elseif(o3.y == lowest)then
low = math.min(o1.y, o2.y, o4.y, o5.y);
elseif(o4.y == lowest)then
low = math.min(o1.y, o2.y, o3.y, o5.y);
elseif(o5.y == lowest)then
low = math.min(o1.y, o2.y, o3.y, o4.y);
end

–Determine which was the highest and then find the
–next highest.
if(o1.y == highest)then
high = math.max(o2.y, o3.y, o4.y, o5.y);
elseif(o2.y == highest)then
high = math.max(o1.y, o3.y, o4.y, o5.y);
elseif(o3.y == highest)then
high = math.max(o1.y, o2.y, o4.y, o5.y);
elseif(o4.y == highest)then
high = math.max(o1.y, o2.y, o3.y, o5.y);
elseif(o5.y == highest)then
high = math.max(o1.y, o2.y, o3.y, o4.y);
end
–Check each object to see which one wasn’t assigned
–to highest, high, low, or lowest

if(o1.y ~= highest and o1.y ~= high and o1.y ~= middle
and o1.y ~= low and o1.y ~= lowest)then

middle = o1.y;

elseif(o2.y ~= highest and o2.y ~= high and o2.y ~= middle
and o2.y ~= low and o2.y ~= lowest)then

middle = o2.y;

elseif(o3.y ~= highest and o3.y ~= high and o3.y ~= middle
and o3.y ~= low and o3.y ~= lowest)then

middle = o3.y;

elseif(o4.y ~= highest and o4.y ~= high and o4.y ~= middle
and o4.y ~= low and o4.y ~= lowest)then

middle = o4.y;

elseif(o5.y ~= highest and o5.y ~= high and o5.y ~= middle
and o5.y ~= low and o5.y ~= lowest)then

middle = o5.y;

end

–Okay, so now that we know the order from lowest
–to highest, we can order their drawing by
–bringing them to the front with toFront(),
–starting with the lowest (so that it gets
–pushed down by the next lowest, and so on, until
–highest is on top of the display

–Find the lowest object and bring it to front first
if(o1.y == lowest)then
o1:toFront();
elseif(o2.y == lowest)then
o2:toFront();
elseif(o3.y == lowest)then
o3:toFront();
elseif(o4.y == lowest)then
o4:toFront();
elseif(o5.y == lowest)then
o5:toFront();
end

–Find the next lowest object and bring it to front second
if(o1.y == low)then
o1:toFront();
elseif(o2.y == low)then
o2:toFront();
elseif(o3.y == low)then
o3:toFront();
elseif(o4.y == low)then
o4:toFront();
elseif(o5.y == low)then
o5:toFront();
end

–Find the middle object and bring it to front third
if(o1.y == middle)then
o1:toFront();
elseif(o2.y == middle)then
o2:toFront();
elseif(o3.y == middle)then
o3:toFront();
elseif(o4.y == middle)then
o4:toFront();
elseif(o5.y == middle)then
o5:toFront();
end

–Find the 2nd highest object and bring it to front fourth
if(o1.y == high)then
o1:toFront();
elseif(o2.y == high)then
o2:toFront();
elseif(o3.y == high)then
o3:toFront();
elseif(o4.y == high)then
o4:toFront();
elseif(o5.y == high)then
o5:toFront();
end

–Find the highest object and bring it to front last
if(o1.y == highest)then
o1:toFront();
elseif(o2.y == highest)then
o2:toFront();
elseif(o3.y == highest)then
o3:toFront();
elseif(o4.y == highest)then
o4:toFront();
elseif(o5.y == highest)then
o5:toFront();
end

end[/lua]

Whew. That was more code than I thought it’d be =P. Hope that gave you an idea of how to do that, but take it with a grain of salt - I’m still pretty new to corona myself ;). [import]uid: 117794 topic_id: 24464 reply_id: 99377[/import]

Wow thanks… [import]uid: 40786 topic_id: 24464 reply_id: 99429[/import]