Handling Depth?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
timmcd
Prole
Posts: 8
Joined: Fri Dec 25, 2009 12:07 am

Handling Depth?

Post by timmcd »

Hello! I am new to both Lua and Love, and I was wondering how you guys manage drawing depth of images/ the 'z' axis? Do you just have a specific drawing order? Ie: Background -> Player -> Overlay? But what if you need to change it around?
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Handling Depth?

Post by bmelts »

There's a tutorial on drawing order on the wiki; that might provide some guidance.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Handling Depth?

Post by Jasoco »

Well, Löve will draw stuff in the order you call for it.

So the easiest way is just to call everything in the order you want to layer them from back to front.

If you want to get techy, dump all the stuff you want to draw into a table, include a zindex variable, then use a sorting function to reorder the table rows by zindex then run through the table and draw the stuff in that order. With that method you could make pseudo-3d side-scrolling beat-em-up games like the old TMNT and Simpsons arcade games which used this method to make sure a character higher up on the screen (Further back) was drawn first with everything else drawn over it.
User avatar
Dr. Peeps
Citizen
Posts: 57
Joined: Sat May 28, 2016 12:57 am
Location: British Columbia, Canada

Re: Handling Depth?

Post by Dr. Peeps »

Is it not possible to use the OpenGL z depth at all in Love then? I'm currently working on some shaders, and it would be nice to use the z coordinates that are automatically passed to the shaders anyway (which I assume are always sent as zero from Love?), rather than have to send them separately myself. I can think of plenty of cool shader effects that could be based on z-order!
Trebgarta
Prole
Posts: 33
Joined: Mon May 23, 2016 5:21 pm

Re: Handling Depth?

Post by Trebgarta »

You need a depth buffer.

Which means you need to ffi import SDL and import gl functions to create one.

Look at how love3d does it.
Post Reply

Who is online

Users browsing this forum: No registered users and 143 guests