Page 1 of 1

love.mouse.isDown

Posted: Wed Nov 05, 2014 11:26 pm
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?

Re: love.mouse.isDown

Posted: Thu Nov 06, 2014 12:14 am
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 :)

Re: love.mouse.isDown

Posted: Thu Nov 06, 2014 1:04 am
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. :)