Page 1 of 1

keyboard.isDown help

Posted: Sat Apr 22, 2017 3:59 pm
by Andrew4Lyf
I have this code:

if love.keyboard.isDown('b') then
if playerRotated == false then
player.width = player.width * 2;
player.height = player.height / 2;
playerRotated = true;
else
player.width = player.width / 2;
player.height = player.height * 2;
playerRotated = false;
end
end

Which rotates a rectangle back and forth. How I do I make it so that instead of it cycling through rotations a million times while the B button is down, it will register b as being pressed only once even if it is being held down? That way it cycles through a rotation once, since you've only pressed b once?

Re: keyboard.isDown help

Posted: Sat Apr 22, 2017 5:35 pm
by Sir_Silver
You want to use the keypressed callback instead of the isDown function.

Code: Select all

function love.keypressed(key)
    --Your code here
end