Snippet: Click Grid

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Snippet: Click Grid

Post by Xcmd »

Code: Select all

function load()
	local f = love.graphics.newFont(love.default_font, 12)
	love.graphics.setFont(f)
	
	mouseClickText = "Mouse Clicked at: 0, 0"
	mouseX = 0
	mouseY = 0
end

function update(dt)
	if love.mouse.isDown(love.mouse_left) then
		x = love.mouse.getX()
		y = love.mouse.getY()
		if love.mouse.getY() < 576 then -- only needed for screens not evenly divisible by 32
			mouseX = math.floor(x / 32)
			mouseY = math.floor(y / 32)
			mouseClickText = "Mouse Clicked at: ".. mouseX .. " (" .. x .. ")" ..", ".. mouseY .. " (" .. y .. ")"
		end
	end
end

function draw()
	love.graphics.draw(mouseClickText, 5, 15)
	love.graphics.rectangle(1, mouseX * 32, mouseY * 32, 32, 32)
end
Click and drag and the square aligns itself to an invisible grid. Part of a project I have in mind.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Snippet: Click Grid

Post by rude »

Dot loveified.
Attachments
snapgrid.love
(611 Bytes) Downloaded 192 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Snippet: Click Grid

Post by bartbes »

Ah.. that nice love icon on my desktop...
User avatar
Xcmd
Party member
Posts: 211
Joined: Fri Feb 13, 2009 10:45 pm

Re: Snippet: Click Grid

Post by Xcmd »

rude wrote:Dot loveified.
Thanks, rude. :D
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest