Fast way to draw large number of quads?
Posted: Sat Jun 18, 2011 9:10 pm
The adventure continues!
Thanks to my last question, I got schooled in how to draw a more efficient map. And it worked! I implemented a "spatial hash" and all is right with the world... except for one thing.
The framerate craters when I zoom out, I assume because LOVE has to start drawing way more quads. If you load the game and hit the letter "o" to zoom "out" (clever, right?) you'll see what I mean. The reverse is also true: zoom in ("i"), showing less, and the framerate shoots up.
I'd really like to be able to zoom out to a stupid level of detail and keep framerates high. Is there some way to generate quads on the fly that consist of smaller quads joined together, perhaps? Or some other approach that will work?
There are two parts, currently, to drawing the tiles. One function creates the x,y boundaries, and the other function goes through the hash drawing every tile that's on the screen.
Boundary part:
(Using math.ceil seemed to lower the framerate, so I use math.floor above and add/subtract 1 below to make sure the edge tiles don't flicker instead of using math.ceil. That may have been my imagination.)
Edited to add: Forgot to mention that the framerate still randomly craters and then goes back up. If it happens to you too please let me know so I know I'm not crazy. Any thoughts on that still welcome.
Thanks to my last question, I got schooled in how to draw a more efficient map. And it worked! I implemented a "spatial hash" and all is right with the world... except for one thing.
The framerate craters when I zoom out, I assume because LOVE has to start drawing way more quads. If you load the game and hit the letter "o" to zoom "out" (clever, right?) you'll see what I mean. The reverse is also true: zoom in ("i"), showing less, and the framerate shoots up.
I'd really like to be able to zoom out to a stupid level of detail and keep framerates high. Is there some way to generate quads on the fly that consist of smaller quads joined together, perhaps? Or some other approach that will work?
There are two parts, currently, to drawing the tiles. One function creates the x,y boundaries, and the other function goes through the hash drawing every tile that's on the screen.
Boundary part:
Code: Select all
function setGrid()
global.gridXStart = math.floor((global.camera.centerX - (global.screenW/2/global.scale)) / global.spriteSize)
global.gridXEnd = math.floor((global.camera.centerX + (global.screenW/2)/global.scale) / global.spriteSize)
global.gridYStart = math.floor((global.camera.centerY - (global.screenH/2)/global.scale) / global.spriteSize)
global.gridYEnd = math.floor((global.camera.centerY + (global.screenH/2)/global.scale) / global.spriteSize)
end
Code: Select all
function drawStuff()
local theX
local theY
for theX = global.gridXStart - 1, global.gridXEnd + 1, 1 do
for theY = global.gridYStart - 1, global.gridYEnd + 1, 1 do
if theX > 0 and theY > 0 and global.spriteGrid[theX][theY] ~= nil then
global.spriteGrid[theX][theY]:draw()
end
end
end
end