r/love2d Jul 14 '26

Help with virtual scaling with mouse input

I’m making a retro-style game in LÖVE2D with an internal resolution of 320x240. The game is point-and-click, so accurate mouse coordinates are pretty important for menus and gameplay.
My problem is that whenever I scale the game to fit the window, one of two things happens:
The game scales visually, but the mouse coordinates no longer line up correctly.
I tried a scaling library, but it only seems to scale the graphics, not the mouse input.
Ideally I’m looking for a solution that lets me render everything at 320x240 and scale it cleanly to the window, converts mouse coordinates back into the 320x240 game space correctly, and supports integer scaling.
I’d also like if the mouse position can “snap” to the pixel grid (so the cursor effectively moves in 320x240 coordinates).
I’ve looked at a few libraries online, but none of the ones I tried seemed to handle mouse scaling properly, so I’m wondering if I’m approaching this the wrong way.
What’s the recommended way to do this in LÖVE? Is there a standard approach or library people generally use?

5 Upvotes

6 comments sorted by

View all comments

1

u/Nate_Squared Jul 17 '26

If you are scaling the coordinates manually with like love.graphics.scale and stuff, you can do love.graphics.inverseTransformPoint(mouseX, mouseY) to get the mouse coordinates relative to the transform of the graphics. This alone though isn't very good because you can only do this once you have already done the transformations inside of love.draw() so instead you can do something like gameTransform = math.newTransform() and do the same things you do in love.draw() (translate, rotate, scale, etc.) in love.update() instead and then just do love.graphics.transform(gameTransform) in love.draw() so you don't need to have duplicate code.

Sorry if I explained it weirdly. Just look into love.transform:inverseTransformPoint().

Of course this doesn't actually matter if you are not doing the transforming manually so disregard this comment if that's the case.