first problem

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.
1stAnd10
Prole
Posts: 22
Joined: Tue Nov 25, 2008 2:09 pm

Re: first problem

Post by 1stAnd10 »

Someone else posted this code originally on the forum so full credit needs to be given to them. Sorry if any typos, doing this from memory.

function mousepressed(x, y, button)
-- left mouse button clicked
if love.mouse_left then
-- check if click was on a body on screen
if intersects(x, y, body:getX(), body:getY(), 32) -- assuming 32 is the radius of the circle body you're checking against
-- do something
end
end
end

function intersects(x1, y1, x2, y2, r)
local dx = x1 - x2
local dy = y1 - y2
return (dx*dx+dy*dy) < (r*r)
end
Post Reply

Who is online

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