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?
Question about depth (Z-axis)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Question about depth (Z-axis)
I dont think that using either vector3's or zindex property will have make considerable difference so go with what you feel is right.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 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
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
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests