[Semi Solved. There is a great library than handles all this for you.]
hey! If anyone finds this via search, check out kikito's library, which he discusses in this thread! -- viewtopic.php?f=4&t=78216&p=173448#p173448
------------------------------------------------------
Hey, folks! first post.
So. the camera tutorial here http://love2d.org/wiki/Tutorial:Camerasis phenomenal.
It teaches you how to create a camera which can, among other things, rotate via the upper left corner, like this
and says, essentially, if you want to be able to do this:
then do some math.... well, I've been racking my brain to find the answer, but I can not figure out how to perform the correct shift. Can anyone help me out?
Rotating the camera from the center rather than the top left
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 19
- Joined: Sat Sep 06, 2014 8:50 pm
Re: Rotating the camera from the center rather than the top
Try using [wiki]love.graphics.push[/wiki], [wiki]love.graphics.pop[/wiki], [wiki]love.graphics.translate[/wiki] and [wiki]love.graphics.rotate[/wiki] in tandem. Love.graphics.push will save the current graphics translation so you can draw objects properly after the rotation. Love.graphics.pop will load that translation. The other two are fairly self-explanatory.
Let me know if this works.
Edit: Thanks to Daedalus for further explaining. I'm not in peak condition right now, so my descriptiveness is somewhat suspect.
Code: Select all
love.graphics.push();
love.graphics.translate(-(love.graphics.getWidth()/2),-(love.graphics.getHeight()/2));
love.graphits.rotate(90);
--insert your code here
love.graphics.pop();
--insert your interface code here
Edit: Thanks to Daedalus for further explaining. I'm not in peak condition right now, so my descriptiveness is somewhat suspect.
Last edited by furi on Sun Sep 07, 2014 1:22 am, edited 1 time in total.
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: Rotating the camera from the center rather than the top
To clarify, love.graphics.translate moves the camera (or the coordinate system, depending on how you see it). The posted code will place the 0,0 coordinate in the centre of the screen, so you will need to shift everything you draw by the same amount to still have it on the right position on the screen. It might be easier to assign local variables instead of calling getWidth and getHeight for every draw call.
Love.graphics.rotate then simply rotates the camera around the 0,0 coordinate, which with this code now is the centre of the screen.
Love.graphics.rotate then simply rotates the camera around the 0,0 coordinate, which with this code now is the centre of the screen.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 9 guests