How to get double-tap

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
Joined: Thu Dec 10, 2020 1:57 am

How to get double-tap

Post by Gunroar:Cannon() »

Just wondering how one would go about getting a double tap (with keys), instead of it registering as a single tap?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: How to get double-tap

Post by milon »

If you're talking keyboard, I believe you have to manually check for that. Here's one way:
Use love.keypressed to register key presses in a table, and also store a timer in it. When a key is pressed, check the timer. If it's a short enough time span, call your "double tap" function. Otherwise, update the key's timer in the table, and optionally call your single-press function (or wait until the timer expires, then decided if it's single or double).
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
darkfrei
Party member
Posts: 1168
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to get double-tap

Post by darkfrei »

For mouse:

Code: Select all

function love.draw()
	love.graphics.print (tostring(mousepressed_presses), 0, 40)
	love.graphics.print (tostring(mousereleased_presses), 0, 80)
end

function love.mousepressed( x, y, button, istouch, presses )
	mousepressed_presses = presses
end

function love.mousereleased( x, y, button, istouch, presses )
	mousereleased_presses = presses
end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests