## [library] gamera - A camera system for LÖVE - v1.0.1 is out

kolorguild
Prole
Posts: 3
Joined: Wed May 13, 2015 2:19 pm

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is

HI all,

I'm new to Love2d (and forum) and am still feeling my way through it. I'm trying to get a gamera set up but aren't getting what the sample file is saying. Could someone possibly show me how to set up the simplest gamera possible? The readme isn't very clear for a newbie on whether to use love.update, love.draw or love.load functions for each set of code. Apologies if I'm coming across as a pain. Haha...

meowman9000
Prole
Posts: 15
Joined: Thu Mar 10, 2016 3:47 pm

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

Does this Gamera do a split view, for coop games by any chance?

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

@meowman9000: you can create several cameras, and make each one track one player. There are several limitations:
• Gamera will not "automatically merge the viewports when the players are near each other". If you want that functionality, you will have to do it yourself (for example by using just one camera, extending its viewport and hiding the other camera)
• Gamera only supports rectangular viewports. If you want to make other kinds of viewports (for example, splitting the screen with a non-vertical line, maybe with an inclination depending on the player's orientation) that's also possible, but not provided by default (you would have to render both cameras into canvases and then merge them).
@kolorguild: I am sorry but I somehow missed your post from last year. I have just read it when I got the one from mewman9000. Do you still need help with gamera?
When I write def I mean function.

meowman9000
Prole
Posts: 15
Joined: Thu Mar 10, 2016 3:47 pm

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

Awesome, that will work perfectly. Thanks for the help.

meowman9000
Prole
Posts: 15
Joined: Thu Mar 10, 2016 3:47 pm

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

I've got a question, I cant seem to get the cam:draw(function(l,t,w,h) to properly filter non-visible elements. First problem is it gives me an error if I pass in numbers manually, like cam:draw(function(0,0,800,600); main.lua:46: <name> or '...' expected near '200'.

Then if I pass in a variable with those parameters it still shows everything no matter what I pass in.

Any examples on how to properly utilize this, the performance is terrible when I'm drawing everything regardless of whether its visible or not.

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

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.
When I write def I mean function.

meowman9000
Prole
Posts: 15
Joined: Thu Mar 10, 2016 3:47 pm

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

Wow thanks again for the help, using bump seems like a cool way of deciding what to draw. I'm going to have to try it and see what kind of performance I can get out of it.

endlesstravel
Prole
Posts: 9
Joined: Fri Apr 01, 2016 10:38 am

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

gamera.lua is reall greate camera system and I'm so gald to know it update !
However, I am come acorss a confuse things in my game.
gif about the problem
show.gif (1.03 MiB) Viewed 2607 times
So, I'm extract code snippet to build a ".love" file and record it below.
gameraTest.love
love project
Runtime environment : love-0.10.1-win32
Thing goes like this:
I want make two viewport on my game to show the same map. And, the first one draw on left , seconde one draw on right.
I use the same gamera object draw twice in function "love.draw".
But, left windows can't move to top left corner.
One the other hand , if I add "else" in line 58, left viewport is ok which just drawing one viewport one the game window.

Ps: If I modify the code "cam:setScale(2)" in line 56 to a large number, camera position will far away form position (0, 0) to lower right corner

it maybe a bug or just a case of using the wrong code.
I con't figure it out.
May be some one can tall me what happend if it's convenient.
Last edited by endlesstravel on Sat Apr 02, 2016 12:59 am, edited 7 times in total.
- Is life always this hard,or is it just when you're a kid?
- Always like this.

kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Contact:

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

@endlesstravel: you forgot to include the zip file. It's also more convenient for every one if you make a .love file instead of a zip (please try that it works before uploading). Finally, it would really help if you explained in detail what was confusing you. If you just say "I came across confuse things" it is probable that no one will help you. Make a list of what you expected, what did you get instead, and what have you tried.
When I write def I mean function.

endlesstravel
Prole
Posts: 9
Joined: Fri Apr 01, 2016 10:38 am

### Re: [library] gamera - A camera system for LÖVE - v1.0.1 is out

kikito wrote:@endlesstravel: you forgot to include the zip file. It's also more convenient for every one if you make a .love file instead of a zip (please try that it works before uploading). Finally, it would really help if you explained in detail what was confusing you. If you just say "I came across confuse things" it is probable that no one will help you. Make a list of what you expected, what did you get instead, and what have you tried.
Oh, It maybe lost link when I submit it from draft. Thank you for reminding. I'm already upload it again.
My English is not very good , but I am working on it .

Thing goes like this:
I want make two viewport on my game to show the same map. And, the first one draw on left , seconde one draw on right.
I use the same gamera object draw twice in function "love.draw".
But, left windows can't move to top left corner.
One the other hand , if I add "else" in line 58, left viewport is ok which just drawing one viewport one the game window.
- Is life always this hard,or is it just when you're a kid?
- Always like this.

### Who is online

Users browsing this forum: No registered users and 4 guests