camera zoom. And button clicking

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
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

camera zoom. And button clicking

Post by baconhawka7x »

I have my camera zoomed by 0.3. And I have a GUI system, where I want to test if the player is clicking on 'v.text'.

This is under love.mousepressed(x,y)
so if I have..

Code: Select all

if x > v.x and
x < v.x + medium:getWidth(v.text) and
y > v.y and
y < v.y + medium:getHeight() then
   click the button 
end
So, how would I change that so that it works with the camera zoom? (camera.scaleX,camera.scaleY).
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: camera zoom. And button clicking

Post by juno »

baconhawka7x wrote:I have my camera zoomed by 0.3. And I have a GUI system, where I want to test if the player is clicking on 'v.text'.

This is under love.mousepressed(x,y)
so if I have..

Code: Select all

if x > v.x and
x < v.x + medium:getWidth(v.text) and
y > v.y and
y < v.y + medium:getHeight() then
   click the button 
end
So, how would I change that so that it works with the camera zoom? (camera.scaleX,camera.scaleY).
This might work..
Multiply the text width and height by the camera scale.

Code: Select all

if x > v.x and
x < v.x + (medium:getWidth(v.text) * camera.scaleX) and
y > v.y and
y < v.y + (medium:getHeight()  * camera.scaleY) then
   click the button 
end
wat ya mean she's in another castle!?
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: camera zoom. And button clicking

Post by dreadkillz »

You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: camera zoom. And button clicking

Post by baconhawka7x »

dreadkillz wrote:You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.
Can I get a link?
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: camera zoom. And button clicking

Post by josefnpat »

baconhawka7x wrote:
dreadkillz wrote:You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.
Can I get a link?
Yes

vrld's hump.camera:
https://www.google.com/search?sourceid= ... ump.camera

dreadkillz camera:
https://www.google.com/search?sourceid= ... llz+camera
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: camera zoom. And button clicking

Post by baconhawka7x »

uhh...All I'm seeing are more camera libraries.
User avatar
dreadkillz
Party member
Posts: 223
Joined: Sun Mar 04, 2012 2:04 pm
Location: USA

Re: camera zoom. And button clicking

Post by dreadkillz »

You don't have to use them, just look at the code to get an idea of how it works. Here's a snippet that he has to convert coordinates between the "world" coordinates and "camera" coordinates:

Code: Select all

function camera:cameraCoords(x,y)
	local w,h = love.graphics.getWidth(), love.graphics.getHeight()
	x,y = vec.rotate(self.rot, x-self.x, y-self.y)
	return x*self.zoom + w/2, y*self.zoom + h/2
end

function camera:worldCoords(x,y)
	local w,h = love.graphics.getWidth(), love.graphics.getHeight()
	x,y = vec.rotate(-self.rot, vec.div(self.zoom, x-w/2, y-h/2))
	return x+self.x, y+self.y
So when you want your mouse to click a zoomed out or in box, you would want to convert the mouse coordinates into world coordinates, and then compare it to your box coordinates.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: camera zoom. And button clicking

Post by baconhawka7x »

thank you dreadkillz.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 214 guests