How to check if 2 keys are down?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
How to check if 2 keys are down?
I noticed that my player goes vertical if holding A and D, now i want to change the characters picture to a vertical picture if the 2 keys are down, but how do i detect if the 2 are down?
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: How to check if 2 keys are down?
Code: Select all
if love.keyboard.isDown('a') and love.keyboard.isDown('d') then
--both keys are pressed
end
Re: How to check if 2 keys are down?
You can also do
Code: Select all
love.keyboard.isDown( 'a' and 'd' )
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
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: How to check if 2 keys are down?
Can you? 'a' and 'd' just returns true, doesn't it (regardless of what strings you put in anyway), so how would love.keyboard.isDown check against just a boolean?
Re: How to check if 2 keys are down?
It works. Of course, you would have to do if love.keyboard.isDown( 'a' and 'd' ) then, but yes, it does work.
- Attachments
-
- main.lua
- Simple example
- (372 Bytes) Downloaded 100 times
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
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: How to check if 2 keys are down?
Hmm, that doesn't seem to work for me though. If I press just 'd' it already says "You did it!", it doesn't see I haven't pressed 'a'.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How to check if 2 keys are down?
"'a' and 'd'" returns 'd', so that's why that works. What he's confused with is that you can pass both to isDown and it will check if either is down.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to check if 2 keys are down?
Just to be super-extra clear:
is NOT a substitute for
(instead, it's a weird way of saying )
On the other hand,
IS a substitute for
Code: Select all
love.keyboard.isDown( 'a' and 'd' )
Code: Select all
love.keyboard.isDown('a') and love.keyboard.isDown('d')
Code: Select all
love.keyboard.isDown( 'd' )
On the other hand,
Code: Select all
love.keyboard.isDown( 'a', 'd' )
Code: Select all
love.keyboard.isDown('a') or love.keyboard.isDown('d')
Help us help you: attach a .love.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: How to check if 2 keys are down?
As a follow up to the great response of the Great Robin, I would just like to mention this part of PiL about logical operators, which is worth reading.
Re: How to check if 2 keys are down?
My bad, sorry for any confusion! Glad that this is cleared up.
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
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 11 guests