Question about depth (Z-axis)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
ElmuKelmuZ
Prole
Posts: 14
Joined: Sat Sep 01, 2012 7:43 pm

Question about depth (Z-axis)

Post by ElmuKelmuZ »

I'm writing some sort of an engine/framework on top of Löve, and have a question.

I have a Vector2 pseudoclass( https://gist.github.com/Elmuti/b1d37f2b5784be76a683 )that I use for Position and Velocity.

My framework/engine will be very object oriented, meaning that I will have UI classes such as Frames, Textboxes, Textlabels etc.
However I know that I need a depth system to define how all the 2d objects on screen layer on top of eachother.
I was wondering if I should just have a ZIndex property in all drawn classes that defines the drawing order, or if I should use Vector3's instead, and having the Z-axis as depth. Or maybe even a completely different approach.

What do you guys think I should do?
Relazy
Citizen
Posts: 51
Joined: Thu Jul 10, 2014 11:10 pm

Re: Question about depth (Z-axis)

Post by Relazy »

ElmuKelmuZ wrote: However I know that I need a depth system to define how all the 2d objects on screen layer on top of eachother.
I was wondering if I should just have a ZIndex property in all drawn classes that defines the drawing order, or if I should use Vector3's instead, and having the Z-axis as depth.
I dont think that using either vector3's or zindex property will have make considerable difference so go with what you feel is right.
I have a UI system like yours that uses zindex, I draw my items as such:

Code: Select all

--@main.lua
function table.zsort(t)
  local a = {}
  for _,n in pairs(t) do table.insert(a, n) end
	table.sort(a,function(a,b) return a.zmap < b.zmap end)
  return a
end
--@ui:draw()
for i,v in ipairs(table.zsort(self.items)) do 
v:draw()
end
if you wanted to use vectors instead:

Code: Select all

--@ui
function self:sortOrder(t)
  local a = {}
  for _,n in pairs(t) do table.insert(a, n) end
	table.sort(a,function(a,b) return a.vector.z < b.vector.z end)
  return a
end
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests