love.graphics.scale() and cursor position

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
tomshreds
Party member
Posts: 101
Joined: Thu Oct 18, 2012 8:49 pm

love.graphics.scale() and cursor position

Post by tomshreds »

Hi,

I'm trying to use

Code: Select all

love.graphics.scale()
but since I use it mouse position is off. What could I do to use proper mouse positions?

Each time I click, it clicks on the offset position of

Code: Select all

scale()
.

Any ideas of what I should do?

I tried

Code: Select all

TLfres
but it didn't do the trick and does the same problem. (I also posted in that thread).

Thanks and have a nice day!
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: love.graphics.scale() and cursor position

Post by micha »

You can simply divide the mouse coordinates by the scale factor.
Example: Scaling by factor 3 means that the mouse x-coordinate 150 is the x-coordinate 150/3=50 in your game coordinates.

However this will only work if you do not also use translate. In that case, you'd have to keep track of all transformations.
tomshreds
Party member
Posts: 101
Joined: Thu Oct 18, 2012 8:49 pm

Re: love.graphics.scale() and cursor position

Post by tomshreds »

micha wrote:You can simply divide the mouse coordinates by the scale factor.
Example: Scaling by factor 3 means that the mouse x-coordinate 150 is the x-coordinate 150/3=50 in your game coordinates.

However this will only work if you do not also use translate. In that case, you'd have to keep track of all transformations.
Ok thanks, I'll try this out!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests