Attached is an image to show my point. I am trying to create a draw only the visible blocks system for a game I am working on. Using code like this:-
Code: Select all
function world:update()
for i=1, #worldBlocks do
if worldBlocks[i].x * self.blockSize >= PlayerCam.x and worldBlocks[i].x * self.blockSize < love.graphics.getWidth()
and worldBlocks[i].y * self.blockSize >= PlayerCam.y and worldBlocks[i].y * self.blockSize < love.graphics.getHeight() then
worldBlocks[i].vis = true
else
worldBlocks[i].vis = false
end
end
end
function world:draw()
for i=1, #worldBlocks do
if worldBlocks[i].vis then
love.graphics.draw(worldBlocks[i].id.img, worldBlocks[i].x * self.blockSize, worldBlocks[i].y * self.blockSize )
end
end
end
Now, while this appears to definitely improve the fps drop that I was experiencing without including this, it still isn't as good as I was expecting. Is this fps drop of around 50% in this case, or even 60-70% in other cases (more blocks drawn on screen) to be expected simply because of the volume of items being drawn? I have the base level start randomized to start at different points as well, if the blocks are all not visible on the screen the fps still seems to drop. Is this to do with table lookups or something then because of the lightweight logic in draw?
These blocks will be destroyable and will all have collision properties at some point as well.
Does anyone have better methods for engineering this? At the moment the block count is quiet small as well. I have attached my love file as well. Would really appreciate any pointers
Thanks,
Pash