Page 1 of 1
How to shift an object's layer?
Posted: Tue Aug 06, 2013 9:06 pm
by LuaMaster
Hello.
I have a question. How would I make object x be infront of object y, besides drawing x first? Like, if I wanted to change it later, what function would I use.
Re: How to shift an object's layer?
Posted: Tue Aug 06, 2013 9:14 pm
by Helvecta
Drawing order is pretty much the only way to put one thing in front of another. I suggest making a depth array, with each entry in the array representing a drawable object. Then in a drawing function you would establish a for loop to draw each object in the array from last to first so that the first in the depth array is drawn last (therefore drawn on top).
With that in place you could just make depth[1] the object you want in front of depth[2], depth[3], etc.
I'd write a simple example for you but my hand's sliced up right now and it's a real pain programming when you're typing 30WPM.
EDIT: Went ahead and wrote a sample for you, it features a slightly different but equally efficient way of doing layers. Use up and down keys to change layers. Sorry I didn't comment on it, my hand ..
Re: How to shift an object's layer?
Posted: Wed Aug 07, 2013 12:48 am
by LuaMaster
Wow thanks, this actually solves ANOTHER problem I was having, along with the ZIndex! From a glance at your code, you're telling what is going to be drawn outside of love.draw, AND with a ZIndex
Re: How to shift an object's layer?
Posted: Wed Aug 07, 2013 7:52 pm
by Helvecta
Yep yep!
Since the zIndex of each picture could change from frame to frame I stuck it in the love.update function; it's a pretty good idea to keep code in its relevant function (drawing stuff stays in love.draw, things like variables that can change from frame to frame stays in love.update, etc).