[SOLVED] Custom Cursors and Window Scaling

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.
Post Reply
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

[SOLVED] Custom Cursors and Window Scaling

Post by Zorochase »

Hello,
Recently, I've been having an issue with custom cursors and love.graphics.scale. I have a custom pointer that, while the scale is set to 1, the image of the pointer and the actual cursor (hidden) match up fine. However, when I scale the window and all of the graphics using love.graphics.scale, the custom pointer image gets bigger as it should, but it no longer matches up with the real cursor's position. It ends up jumping off-screen, and I have to move the real cursor to get the custom cursor back on-screen. I also noticed that the bigger the window scale gets, the faster the custom pointer moves. The one upside to this is that the custom cursor still snaps to the 1 pixel grid. I tried scaling the cursor separately, and while I was able to get the two to match up again, the custom cursor moved independently of the pixel grid. How can I get them to match up AND stick within the 1 pixel grid?

Sorry I dragged this out so long, hopefully I didn't waste too much of your time :P
Last edited by Zorochase on Fri Aug 18, 2017 3:38 am, edited 1 time in total.
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Custom Cursors and Window Scaling

Post by Lafolie »

You need to also scale the cursor position. For example, say your original resolution is 10x10 pixels. At a scale of 1 the ratio of the system cursor to the game cursor is 1:1. Now let's assume you scale your window to 20x20. The scale is now 2:1, that is, for every 2 pixels the system cursor moves, your game cursor needs to move 1 pixel.

Pseudo code:

Code: Select all

cursorPosition = mousePosition / windowScale
This works because whilst your final output to the screen is scaled, all of your drawing is still being done at the original resolution.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.
Zorochase
Prole
Posts: 21
Joined: Sun May 21, 2017 10:40 pm
Contact:

Re: Custom Cursors and Window Scaling

Post by Zorochase »

Lafolie wrote: Fri Aug 18, 2017 12:00 am You need to also scale the cursor position. For example, say your original resolution is 10x10 pixels. At a scale of 1 the ratio of the system cursor to the game cursor is 1:1. Now let's assume you scale your window to 20x20. The scale is now 2:1, that is, for every 2 pixels the system cursor moves, your game cursor needs to move 1 pixel.

Pseudo code:

Code: Select all

cursorPosition = mousePosition / windowScale
This works because whilst your final output to the screen is scaled, all of your drawing is still being done at the original resolution.
Looks like you were right, I've got it now. Thank you!
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests