Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Your Input class is unneeded. #17

Open
gravypod opened this issue Jul 25, 2014 · 3 comments
Open

Your Input class is unneeded. #17

gravypod opened this issue Jul 25, 2014 · 3 comments

Comments

@gravypod
Copy link

I was watching your tutorial and noticed that you created the Input class witch is largely unneeded. You can do the same thing it does more efficiently with

while (Keyboard.next()) {
    char key = Keyboard.getEventCharacter();
    boolean state = Keyboard.getEventKeyState(); // If the key is held down (true) or released (false)
   // TODO: Handle key clicks
}

Another thing to look into is using

int NUM_KEYCODES = Keyboard.getKeyCount();

instead of the current constant.

@agausmann
Copy link

Actually, in his case, the Input class is needed. Since there are multiple components potentially retrieving input, Keyboard.next() will not suffice - the first Component.input() called that uses a while (Keyboard.next()) loop will hog all of the events, and none of the other components will be able to read them (unless they happen between the input() calls.
However, his Input class can be optimized using Keyboard.next() instead of checking every key indiviudally for its state.

@gravypod
Copy link
Author

gravypod commented Aug 6, 2014

Sorry, I was more referring to the loop covering all of the keys. Iterating over every key is unneeded.

@agausmann
Copy link

I agree. If he had used Keyboard.next() instead it could potentially run faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants