love.mouse.isDown

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

love.mouse.isDown

Post by davisdude »

I know the wiki says that it does not detect wu and wd and says to use love.mousepressed and love.mousereleased instead.
However, love.mousereleased does not detect the release of the mouse-wheel either. This forces the use of a round-about method:

Code: Select all

local wu, wd

function love.load()
    wu, wd = false, false
end

function love.draw()
end

function love.update( dt )
    -- Use stuff with wu bool.
    wu = false
    wd = false
end

function love.keypressed( Key )
    if Key == 'wu' then wu = true 
    elseif Key == 'wd' then wd = false end
end
Is this the way to do this, or am I missing something?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: love.mouse.isDown

Post by HugoBDesigner »

Okay, first of all: you REALLY can't detect mouse release with 'wu' and 'wd' because they're technically not buttons. Just look at it while you're scrolling up or down: there is no "middle-term" or pressed/unpressed terms. There is one thing you can do, though: detect the time passed between each time you "press" it. So you can establish a "maximum" speed for scrolling up/down. Also, it is still a mousepress, and not a keypress. What you did there would never work.

Code: Select all

function love.load()
	wu, wd = false, false
	wuT, wdT = 0, 0
	wheelTimer = .25
end

function love.update(dt)
	if wuT > 0 then
		wuT = wuT - dt
	end
	if wdT > 0 then
		wdT = wdT - dt
	end
	
	if wuT <= 0 and wu then
		wuT = 0
		wu = false
	end
	if wdT <= 0 and wd then
		wdT = 0
		wd = false
	end
end

function love.mousepressed(x, y, button)
	if button == "wu" then
		wu = true
		wuT = wheelTimer
	elseif button == "wd" then
		wd = true
		wdT = wheelTimer
	end
end
You only need to adjust "wheelTimer" to whatever value you prefer :)
@HugoBDesigner - Twitter
HugoBDesigner - Blog
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: love.mouse.isDown

Post by davisdude »

HugoBDesigner wrote:Also, it is still a mousepress, and not a keypress. What you did there would never work.
Oh, my bad. I typed it incorrectly while posting to the forums. :oops:

Thanks for the code. :)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests