Page 2 of 4

Re: A very simple camera lib

Posted: Wed Aug 08, 2012 1:28 am
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)

Re: A very simple camera lib

Posted: Wed Aug 08, 2012 9:01 am
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".

Re: A very simple camera lib

Posted: Wed Aug 08, 2012 8:56 pm
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 :)

Re: A very simple camera lib

Posted: Thu Aug 09, 2012 12:37 pm
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.

Re: A very simple camera lib

Posted: Thu Aug 09, 2012 10:33 pm
by kikito
Hi, can you make a .love file?

Re: A very simple camera lib

Posted: Sun Aug 19, 2012 2:59 pm
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.

Re: A very simple camera lib

Posted: Sun Aug 19, 2012 11:18 pm
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 :)

Re: A very simple camera lib

Posted: Mon Aug 20, 2012 8:04 am
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.

Re: A very simple camera lib

Posted: Mon Aug 20, 2012 8:19 am
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 ?

Re: A very simple camera lib

Posted: Mon Aug 20, 2012 8:45 am
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?