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 .
yetneverdone
Party member
Posts: 446 Joined: Sat Sep 24, 2016 11:20 am
Contact:
Post
by yetneverdone » Thu Feb 23, 2017 4:37 am
Hi, in my
love.draw() function, I have:
Code: Select all
love.graphics.push()
love.graphics.translate(0,width/2) -- to center the game view
love.graphics.scale(ratio,ratio)
love.graphics.pop()
and in my
love.update(dt) function:
Code: Select all
local mx = love.mouse.getX()/ratio
local my = love.mouse.getY()ratio
--ps can I do
local mx,my = love.mouse.getPosition()/ratio? I just thought about it this instant
The problem is, without the translate function, it works, but after using the translate function, the mouse(specifically the Y) is off. How would I correct the mouse coordinates? Thanks alot
Positive07
Party member
Posts: 1014 Joined: Sun Aug 12, 2012 4:34 pm
Location: Argentina
Post
by Positive07 » Thu Feb 23, 2017 6:33 am
You subtract the offset first. Graphics translations are not related to mouse coordinates.
You basically do the opposite operations so if you added an offset you subtract it, if you scaled up then you scale down
Code: Select all
local mx = (love.mouse.getX() - tx) / sx
local my = (love.mouse.getY() - ty) / sy
Code: Select all
love.draw = function ()
love.graphics.push()
love.graphics.translate(tx, ty)
love.graphics.scale(sx, sy)
love.graphics.pop()
end
for i, person
in ipairs (everybody)
do
[tab] if not person.obey
then person:setObey(
true )
end
end
love.system.openURL(
github.com/pablomayobre )
yetneverdone
Party member
Posts: 446 Joined: Sat Sep 24, 2016 11:20 am
Contact:
Post
by yetneverdone » Thu Feb 23, 2017 7:01 am
Positive07 wrote: ↑ Thu Feb 23, 2017 6:33 am
You subtract the offset first. Graphics translations are not related to mouse coordinates.
You basically do the opposite operations so if you added an offset you subtract it, if you scaled up then you scale down
Code: Select all
local mx = (love.mouse.getX() - tx) / sx
local my = (love.mouse.getY() - ty) / sy
Code: Select all
love.draw = function ()
love.graphics.push()
love.graphics.translate(tx, ty)
love.graphics.scale(sx, sy)
love.graphics.pop()
end
Thanks. Actually ive tried that before posting here, i rechecked again, it was that i test at the wrong function hahaha. Silly me. Thanks anyways
Users browsing this forum: Google [Bot] , Yolwoocle and 211 guests