You have several missconceptions. Let me try to clarify them.
First, you are not supposed to "fill up" the parameters of the function you pass to cam:draw. Instead, cam:draw fills them up for you when you call it. The reason it does this is that calculating these numbers is a bit difficult (that's why there is a method called cam:getVisible() - those 4 letters are calculated there, and it's not trivia). It would work the same if you did this:
Code: Select all
cam:draw(function()
local x,y,w,h = cam:getVisible()
...
end)
But this is so frequent that gamera just includes those 4 numbers as parameters for your convenience.
Second, gamera doesn't "automatically filter out the elements that you don't want to draw". It just gives you those numbers in the function. Then *you* have to filter out what to draw and what not to draw. gamera can not "automatically guess" what draw instructions can be ignored and which ones can't.
If you are doing a tile-based game, then this is not very difficult. Instead of drawing everything with a loop, like this:
Code: Select all
function drawMap(map)
for row=1, map.width do
for col=1, map.height do
drawTile(map, row, col)
end
end
end
You change that function to look like this:
Code: Select all
function drawMap(map, x,y,w,h)
local left, top = getTileCoords(x,y) -- coordinates of the tile containing the point x,y
local right, bottom = left + w / map.tileWidth, top + h / map.tileHeight
for row=left, right do
for col=top, down
drawTile(map, row, col)
end
end
end
Note that the calculations of left, top, right and bottom will depend on how your tiles are stored, this is just one example. And this is only for the tiles, you will need to do something similar for the entities.
Also, if you are using
bump, or any other library which allows querying the space, like HC, there is usually a way to "get all the elements touching a given rectangle". In bump you can do this:
Code: Select all
function drawVisibleItems(world, l,t,w,h)
local visibleItems, len = world:queryRect(l,t,w,h)
for i=1, len do
drawItem(visibleItems[i])
end
end
That will work for both entities and tiles, assuming that you have introduced all of them in the world.