(SOLVED) Z-Ordering graphical issues.
Posted: Tue Jul 21, 2015 8:35 pm
I'm attempting to Z-order my entities for my game, but the function that I supplied to table.sort seems to be shifting the entity table in some weird way, making the entities onscreen flash.
Just for clarification, my ents table holds every entity in the game (each one has their own z variable) and is then cycled through to check if the entities have draw functions. If they do, it draws them. The bug seems to be that their drawing function doesn't call properly due to table.sort.
This gif shows my game without any z-ordering. Everything stays stable and never disappears. The bullets have a lifespan, so after a certain amount of frames, they're removed from the ents table, which ceases to draw and update it.
This shows my game with the z-ordering function enabled, sorting the table in a way that makes the entities flash. It seems to do it mostly when the entities delete themselves off-screen.
Here's my draw function, complete with the function I also use for z-ordering.
If you want a better idea of what I have, I attached my .love file (if you're brave enough to go into moonscript-compiled lua code). What you want to do when you open the game is to press 0 to go to the debug room (where the gifs above take place), and then press 'p' to open the text menu that you see flashing in the gifs
The drawSort and draw functions are located in lib\mad\madlib.lua. This is the file that houses the library/engine thing I've been working on for the past few months in my spare time.
Thanks for the help!
Just for clarification, my ents table holds every entity in the game (each one has their own z variable) and is then cycled through to check if the entities have draw functions. If they do, it draws them. The bug seems to be that their drawing function doesn't call properly due to table.sort.
This gif shows my game without any z-ordering. Everything stays stable and never disappears. The bullets have a lifespan, so after a certain amount of frames, they're removed from the ents table, which ceases to draw and update it.
This shows my game with the z-ordering function enabled, sorting the table in a way that makes the entities flash. It seems to do it mostly when the entities delete themselves off-screen.
Here's my draw function, complete with the function I also use for z-ordering.
Code: Select all
draw = function(self, cam)
for k, v in pairs(ents) do
cam:draw(function()
if v.draw ~= nil then
return v:draw()
end
end)
end
if debug.debugMode and debug.debugShow then
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("FPS: " .. love.timer.getFPS(), 16, 16)
love.graphics.print("Number of entities: " .. entAmt, 16, 32)
return love.graphics.print("Current room: " .. room, 16, 48)
end
end
drawSort = function(a, b)
if a and b then
return a.z > b.z
end
end
The drawSort and draw functions are located in lib\mad\madlib.lua. This is the file that houses the library/engine thing I've been working on for the past few months in my spare time.
Thanks for the help!