Java OpenGL 2D Game Tutorial - Episode 19 - Player Input

preview_player
Показать описание
Let's make our player move around on the screen.
Don't forget to like, comment, and subscribe for more videos. Thanks for watching!
Рекомендации по теме
Комментарии
Автор

The code for KeyInput.java ahould be:

public void keyPressed(KeyEvent e) {
if ((InputEvent.AUTOREPEAT_MASK & e.getModifiers()) == 0) {
keys[ke.getKeyCode()] = true;
}
}

public void keyReleased(KeyEvent e) {
if ((InputEvent.AUTOREPEAT_MASK & e.getModifiers()) == 0) {
keys[ke.getKeyCode()] = false;
}
}

Otherwise you can get automatic calls to key release when you didn't actually release the key.
Not sure why he didn't have this problem. Must be a Mac thing because I'm on Windows.

greg
Автор

When I hold down a key, the image moves for about a second, and then stops. For it to move again I have to release and press the key again

MoabAssasin
Автор

Changing this in the keyInput class will fix the problem mentioned @asdfghjkl

@Override
public void keyReleased(KeyEvent e) {
if(e.isAutoRepeat()) {
return;
}
keys[e.getKeyCode()] = false;
}

maxb
Автор

dont forget to add "window.addKeyListener(new KeyInput());" to init() in Renderer

maxb
Автор

using awt... how do I bind to alt? (seems to unfocus my window)

eXioStorm
Автор

dude if u want character images, spritesheets of my created, I can share with u for free to improve your game

fatihcenesiz