How to print text that isn't affected by the camera.scale ?

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.
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

Hi ! I use, for the first time in one of my projects, the camera module available here : https://ebens.me/post/cameras-in-love2d ... he-basics/ and I'm very happy with it so far. The only problem is that I don't know how to print or draw something on the screen that is not affected by the camera module.
I currently use the camera.scaleX and camera.scaleY thing with my 2D game so the player can zoom in and out, but the problem is that when he zooms in or out, everything zoom in or out including user interface (how many life the player has, etc), which, of course is a problem.
I can avoid that problem by using camera.scaleX and camera.scaleY as the scale arguments for my print function, but it does not avoid the fact that, when I zoom out, every text position changes and basically moves to the top left corner of the screen (I hope I'm clear).

I'm still a begginer and it's the first time I use this camera module (or any kind of camera really) so if someone can help me with that silly problem, that will be very cool, thanks :)

Edit : I forgot about the second problem. I want my player to be on the middle of the screen so I wrote that
camera.x = (player.x - (screen_width/2))
and
camera.y = (player.y - (screen_height/2))
but when I zoom out the player is not centered anymore as you guys can imagine. How can I correct that too ?

Thanks for your help :)
Last edited by Harrylechienfou on Mon Jul 08, 2019 6:35 pm, edited 1 time in total.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by raidho36 »

You simply reset the camera before drawing it.
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

What do you mean by that and how do I do that ? I'm sorry I'm sure it's a silly question but I'm a begginer :/
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

Oh I think I understand sorry. I guess I have to do a camera:unset() before I print all the texts ?
But what about the second problem ?
TheHUG
Citizen
Posts: 62
Joined: Sun Apr 01, 2018 4:21 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by TheHUG »

the camera origin is the upper left corner? If you can change that, then it would be best to set the origin at the center so that you can just set it to player.x player.y.
If not, then you'll just need to reset the camera's location after you change its scale (apply the same operation)
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: How to print text that isn't affected by the camera.scale ?

Post by PGUp »

use love.graphics.push() before drawing the text and love.graphics.pop() after drawing the text
-
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

Ok thanks for the help everybody. I knew I had to change the camera.x and camera.y settings to include the camera.scale in the formula, but I did not do it the right way. Now it seems to be fixed.
You were very helpfull, thanks a lot.
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

I have another question since were're here : what if I want to use the current mouse position to be the center of the screen when I zoom in/out ? Like for example I put the mouse somewhere on the screen when there is a red dot drawn, and because the mouse is wher the red dot is, it will zoom in/out where the mouse is (at the red dot position), but if after that I move my mouse to a blue dot drawn somewhere on the screen, then it will zoom in/out with the camera centered on this blue dot instead.

I tried different things with love.mouse.getX() and love.mouse.getY() but nothing works. I suspect that is because the mouse position does depend on the camera.x and the camera.y (which is not che case of the player.x and the player.y) since the mouse is drawn seperately from the rest of the game. Not sure though.

What I did with the camera being centered around the character no matter what level of zoom is the following :
camera.x = (player.x) - ((screen_width/2)*camera.scaleX)
camera.y = (player.y) - ((screen_height/2)*camera.scaleY)
But I can't do the same with the camera being centered around the mouse like this :
camera.x = (love.mouse.getX()) - ((screen_width/2)*camera.scaleX)
camera.y = (love.mouse.getY()) - ((screen_height/2)*camera.scaleY)
The problem is that when I zoom in/out, the mouse position on the screen stay the same, which is not the case of everything else's position, including the red dot and the blue dot, I suppose ?
Is that hard to manage ? I have no clue how to fix that.

If you have the solution, I'll be very interested, as I think it will help me to understand lots of stuff.
Thanks :)
User avatar
Harrylechienfou
Prole
Posts: 30
Joined: Tue May 21, 2019 2:02 pm

Re: How to print text that isn't affected by the camera.scale ?

Post by Harrylechienfou »

Does somebody knows how to do such a thing ? :o:
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: How to print text that isn't affected by the camera.scale ?

Post by Jeeper »

Remember that you mouse coordinates are not affected by the camera. So it if your screen in 1920x1080, then your camera.x will be 0-1920, even if you have moved 10 000 pixels to the right.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest