Re: What's everyone working on? (tigsource inspired)
Posted: Wed May 18, 2016 4:10 pm
About losing Z index, that depends on how you're coding. Usually, you just draw everything in a specific order and voilá
I for instance like drawing everything by hand in a specific order. Sure, some cases is good to have a DrawPool like you do, but in others i just prefer to have the values exposed so i can fine adjust where everything should go.Jasoco wrote:The way I deal with Z indexing on images is to throw every single drawable into a table and sort that then draw the objects. Table sorting in Lua is pretty damn fast. I created my own DrawPool library for it too.
I use it in every project I make. It's much easier to deal with drawing when you don't have to worry about what order items have been drawn. Let the DrawPool sort it by their "layer", or "distance from camera" and you're set. Just draw whenever.
But my method lets you fine tune placement better than just calling love.graphics.* functions straight. For instance, it lets you choose what layer to place the drawable. So even if I call a circle first and a square second, if the circle has a higher layer, it's going to draw last and on top. This is useful because you can't always be certain what order entities will be updated and drawn in since for is unpredictable with pairs() and you can't sort unnumbered indexed tables. Only ones with ordered pairs. My DrawPool makes sure I don't have to care. Plus it adds barely any extra time since table.sort is really fast. Plus it helps with any kind of game with any sort of 3D or pseudo 3D style to it like TMNT style brawlers and the like. I initially invented the method when I was toying around with a Star Fox style SuperFX engine.Sulunia wrote:I for instance like drawing everything by hand in a specific order. Sure, some cases is good to have a DrawPool like you do, but in others i just prefer to have the values exposed so i can fine adjust where everything should go.
Code usually gets messier though, so it has that drawback.
Code: Select all
drawPool:push { kind = "rect", x = 100, y = 100, w = 100, h = 100, color = {255,0,0}, layer = 100 }
drawPool:push { kind = "circle", x = 200, y = 120, rad = 80, color = {0,0,255}, layer = 95 }
drawPool:push { kind = "text", x = 50, y = 200, width = 300, align = "center", shadow = true, font = your_font, color = {255,255,255}, layer = 103 }
drawPool:push { kind = "image", x = 80, y = 60, image = fluffyBunny, quad = bunnyQuad[1], rot = 0, sx = 1, sy = 1, iox = 0, ioy = 0, layer = -304.43 }
...
Don't think I'm more knowledgeable than you but I'd def look into it.Jasoco wrote:I'd put it on GitHub but I'd rather someone more knowledgeable look over the code and make sure it looks proper enough before I do that. Plus I'd want to make it more user-friendly. But this works really well.
Agreed, i'm particularly interested aswells-ol wrote:Don't think I'm more knowledgeable than you but I'd def look into it.Jasoco wrote:I'd put it on GitHub but I'd rather someone more knowledgeable look over the code and make sure it looks proper enough before I do that. Plus I'd want to make it more user-friendly. But this works really well.
I opted for a similar approach, in some projects, but using a queue of closures with priority. That way I simply enqueue the drawing snippets without the need to define a specification format to be interpreted.Jasoco wrote:I created my own DrawPool library for it too.