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.
How to shift an object's layer?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How to shift an object's layer?
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 ..
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 ..
- Attachments
-
- depth.love
- (260.2 KiB) Downloaded 139 times
"Bump." -CMFIend420
Re: How to shift an object's layer?
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?
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).
"Bump." -CMFIend420
Who is online
Users browsing this forum: Google [Bot] and 3 guests