dusoft wrote: ↑Thu Mar 02, 2017 5:50 am
great!
will
be respected impact-wise in terms of not drawing anything else beside the selected rectangle?
no, offscreen contents are scissored automatically afaik (the performance difference will be negligible or nonexistent).
Whats more important is not trying to draw things in the first place, or even better, not even reading the data in Lua.
For example, lets say you're drawing a tilemap:
Code: Select all
love.graphics.translate(-camera.x, -camera.y)
for x=1,1000 do
for y=1,1000 do
tiles[x][y]:draw()
end
end
of course this is not how it usually looks for real, but you get the idea, and probably why you don't want to do that.
Heres a better approach, performance-wise:
Code: Select all
love.graphics.translate(-camera.x, -camera.y)
local width, height = love.graphics.getDimensions()
local sx = math.floor(camera.x / TILEWIDTH)
local sy = math.floor(camera.x / TILEWIDTH)
local ex = math.ceil((camera.x + width) / TILEWIDTH)
local ey = math.ceil((camera.x + height) / TILEWIDTH)
for x=sx,ex do
for y=sy,ey do
tiles[x][y]:draw()
end
end
do you get why and how this works?
Keep in mind that you don't even need to think about this until your game starts to lag, or you are thinking about bringing it to some platform where it lags.