A very simple camera lib

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
LaserGuns
Prole
Posts: 33
Joined: Sun Apr 29, 2012 12:55 am

Re: A very simple camera lib

Post by LaserGuns »

WAT.
You do NOT need all of that code :O
Just use this one line:

Code: Select all

love.graphics.translate(-x, -y)
So for example, to translate the camera to the player, use:

Code: Select all

love.graphics.translate(-player.x, -player.y)
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: A very simple camera lib

Post by kikito »

I find that approach too simplistic.

When the player is near the borders of the world, I want the camera "stopping scrolling", so that no "black borders" are seen. And I want it to work with any screen resolution. I also want to be able to ask the camera "give me the rectangle coordinates of what you are currently seeing".
When I write def I mean function.
LaserGuns
Prole
Posts: 33
Joined: Sun Apr 29, 2012 12:55 am

Re: A very simple camera lib

Post by LaserGuns »

kikito wrote:I find that approach too simplistic.

When the player is near the borders of the world, I want the camera "stopping scrolling", so that no "black borders" are seen. And I want it to work with any screen resolution. I also want to be able to ask the camera "give me the rectangle coordinates of what you are currently seeing".
oh, okay. its still handy for someone who wants a quick simple camera though :)
looter
Prole
Posts: 2
Joined: Tue Aug 07, 2012 1:34 pm

Re: A very simple camera lib

Post by looter »

Edit: I fixed this sometime yesterday, you have to set the boundary before you set the viewport, woops. I'm having some troubles getting the camera to bound within my world correctly though, if you would want to help me with that id appreciate it, flashkot already put me on the right track but there are some odd issues I haven't been able to figure out yet.
Last edited by looter on Fri Aug 10, 2012 5:48 am, edited 2 times in total.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: A very simple camera lib

Post by kikito »

Hi, can you make a .love file?
When I write def I mean function.
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: A very simple camera lib

Post by Petunien »

Hi!

I'm pretty confused of how to make the camera scroll using the mouse (level editor).
I tried several ways an possibilities.

Could you show an example of scrolling with the mouse?

So, if I move the mouse in the last right 25px, the camera moves right.

In my tries, I always get troubles with selecting units. It's most likely because the mouse has its x/y in the current cameraview.
"Docendo discimus" - Lucius Annaeus Seneca
thecontrarian42
Prole
Posts: 3
Joined: Sun Aug 19, 2012 10:48 pm

Re: A very simple camera lib

Post by thecontrarian42 »

Petunien wrote:Hi!

I'm pretty confused of how to make the camera scroll using the mouse (level editor).
I tried several ways an possibilities.

Could you show an example of scrolling with the mouse?

So, if I move the mouse in the last right 25px, the camera moves right.

In my tries, I always get troubles with selecting units. It's most likely because the mouse has its x/y in the current cameraview.
I've never used this particular lib, but basically you just put in to your update function to get the mouse position and check if its x and y are greater than or less than certain bounds. like say your window is 800 px wide, you would have an if statement that says something like

Code: Select all

if window width - mouse X coordinate <= 25 then 
  viewport X = viewport X + (dt*15)
end
which will scroll right 15 px every second your mouse is within 25 pixels of the right side of the window.

HOPE THAT HELPS :)
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: A very simple camera lib

Post by Petunien »

Thank you, but I had already a similar system. :)

But my main problem still remains, I can't select anything.

Assumed there's an object's x-coordinate at 200.
When the mouse was clicked, I check for a collision between the mouse's X and the object's X including its width.
It works very well, but if I moved the camera to the right, the mouse still gets its coordinates from the current cameraview.

So mouseX ~= objectX.

Sorry for bad explaining.
"Docendo discimus" - Lucius Annaeus Seneca
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: A very simple camera lib

Post by Roland_Yonaba »

Petunien wrote:Thank you, but I had already a similar system. :)

But my main problem still remains, I can't select anything.

Assumed there's an object's x-coordinate at 200.
When the mouse was clicked, I check for a collision between the mouse's X and the object's X including its width.
It works very well, but if I moved the camera to the right, the mouse still gets its coordinates from the current cameraview.

So mouseX ~= objectX.

Sorry for bad explaining.
Can you provide a *.love file, please ?
User avatar
Petunien
Party member
Posts: 191
Joined: Fri Feb 03, 2012 8:02 pm
Location: South Tyrol (Italy)

Re: A very simple camera lib

Post by Petunien »

Thank you for your offer of assistance, but I think I've solved it.

This image gave me the solution: http://www.liquidfirearts.com/download/ ... inates.jpg

(xnamag.de - JeReT)

- - -

@kikito
The MIT license allows it, but I'd prefer to ask for permission... may I change your library and implement new functions?
"Docendo discimus" - Lucius Annaeus Seneca
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 10 guests