Page 1 of 1

[SOLVED] Custom Cursors and Window Scaling

Posted: Thu Aug 17, 2017 10:23 pm
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

Re: Custom Cursors and Window Scaling

Posted: Fri Aug 18, 2017 12:00 am
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.

Re: Custom Cursors and Window Scaling

Posted: Fri Aug 18, 2017 3:37 am
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!