Where do you check for keyboard input
-
- Prole
- Posts: 15
- Joined: Thu Dec 11, 2008 5:44 am
Where do you check for keyboard input
Just a consensus poll for how everyone does it. I am currently arguing with myself over which to go with and neither side is making much progress. Vote and post what you think...
Re: Where do you check for keyboard input
I check both as they have entirely and incredibly different uses.
When you're checking it inside of a function, like update or draw, you're checking it each time that loop is passed through. When you check the keypressed function, you're checking it only when the key is pressed. They have entirely different uses, although mostly you use keypressed when you want to check one key press at a time and update when you want to be able to press multiple keys.
But you have to use if / end loops properly as well. If you do if / else / end loops with your key presses, it's going to function the same as if you used keypressed. But if you use if / end for each keypress you should be able to achieve the results of multiple button presses.
Anyway, I hope that makes sense.
When you're checking it inside of a function, like update or draw, you're checking it each time that loop is passed through. When you check the keypressed function, you're checking it only when the key is pressed. They have entirely different uses, although mostly you use keypressed when you want to check one key press at a time and update when you want to be able to press multiple keys.
But you have to use if / end loops properly as well. If you do if / else / end loops with your key presses, it's going to function the same as if you used keypressed. But if you use if / end for each keypress you should be able to achieve the results of multiple button presses.
Anyway, I hope that makes sense.
We don't borrow, we don't read, we don't rent, we don't lease, we take the minds!
-
- Prole
- Posts: 15
- Joined: Thu Dec 11, 2008 5:44 am
Re: Where do you check for keyboard input
That makes sense and I'd thought of that before but I just did a test which showed me that keypressed only runs when the key is first pressed down, not any time it is pressed down, which I should've figured but never did for some reason, and now knowing that makes the reasons to use different places for different things make a lot more sense.
Maybe I should change the question to be asking which one people prefer when one is not necessary over the other...
Maybe I should change the question to be asking which one people prefer when one is not necessary over the other...
Re: Where do you check for keyboard input
I use the functions over the callbacks, usually if im looking for a keypress that means im going to update something, and it seems more logical to just do "if left then move (X * dt)" rather than spreading it out and making a messTacticalPenguin wrote:Maybe I should change the question to be asking which one people prefer when one is not necessary over the other...
-
- Prole
- Posts: 15
- Joined: Thu Dec 11, 2008 5:44 am
Re: Where do you check for keyboard input
The bit with the dt makes a lot of sense for movement control.osgeld wrote:I use the functions over the callbacks, usually if im looking for a keypress that means im going to update something, and it seems more logical to just do "if left then move (X * dt)" rather than spreading it out and making a messTacticalPenguin wrote:Maybe I should change the question to be asking which one people prefer when one is not necessary over the other...
It seems each one has its own separate uses which I suppose will just have to annoy me, having the same general functionality split into two different spots....here's to less prestructuredness in 0.6.0.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Where do you check for keyboard input
0.6.0: It's still there, however, you can enable key repeat for the keypressed, and it will return the unicode equivalent of the button(s) pressed, so, keypressed is more of text input and commands, and isDown for code which needs to be run while the key is down.
And I voted both.
EDIT: Thought it might be unclear, key repeat and the unicode character are not triggered by each other, they are both new features.
And I voted both.
EDIT: Thought it might be unclear, key repeat and the unicode character are not triggered by each other, they are both new features.
Re: Where do you check for keyboard input
You always want to check for key presses in the keypressed and keyreleased events! Always! There is no point in doing it within the update loop, this adds a preformance drop that is unnecessary and the exact results can be achieved faster with keypressed/keyreleased.TacticalPenguin wrote:Just a consensus poll for how everyone does it. I am currently arguing with myself over which to go with and neither side is making much progress. Vote and post what you think...
That is the reason keypressed and keyreleased callbacks where added, so you do not have to write a lua loop that runs everyframe. This is cpu expensive people.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Where do you check for keyboard input
This is a matter of personal style, and one could argue that saving every pressed character presents other overhead, which might outweigh the overhead created by using love.keyboard.isDown. Furthermore, on most modern computers resources are not that limited that it really matters.
Once again, despite my tone, I mean no offense.
Once again, despite my tone, I mean no offense.
Re: Where do you check for keyboard input
I'm going by what I learn from websites, personal tests, and concrete evidence, not my opinion.bartbes wrote:This is a matter of personal style, and one could argue that saving every pressed character presents other overhead, which might outweigh the overhead created by using love.keyboard.isDown. Furthermore, on most modern computers resources are not that limited that it really matters.
Once again, despite my tone, I mean no offense.
Source: http://lua-users.org/lists/lua-l/2004-04/msg00164.html (scroll to the section "Binding Lua to C++")
Just want you to realise alot of this stuff isn't my opinion as much as it is the opinions of people who've done alot of research.Source wrote: Avoid using Lua in "every frame" actions as performance drops
dramatically. For example, don't use Lua to do animation updates; set
up parameters for the animation in Lua and do the updates in C/C++
code.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Where do you check for keyboard input
The piece you quoted doesn't have anything to do with this particular situation.
Who is online
Users browsing this forum: No registered users and 9 guests