所以基本上我想做的是使用 LWJGL 现在让我的玩家在游戏中移动。玩家当前正在移动,但在您按住按钮时他并没有继续移动..
公共无效更新(){同时(Keyboard.next()){
if(Keyboard.getEventKey() == Keyboard.KEY_RIGHT) {
if(Keyboard.getEventKeyState()){
System.out.println("KEY DOWN!");
player.playerMovingRight();
}
else{
System.out.println("KEY RELEASED!");
}
}
}
我尝试使用一段时间(Keyboard.getEventKeyState()),但它只会让游戏崩溃,并且它不会识别我是否释放密钥。
那么,如果您按住按钮而不是快速按键来移动,我怎样才能让我的播放器继续移动。如果玩家同时按住 2 个按钮,我将如何使其工作?
更新代码:
public void update(){
while(Keyboard.next()){
//If key escape is down we shut the application down
if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
System.exit(0);
}
//If key up was pressed move up
else if(Keyboard.getEventKey() == Keyboard.KEY_UP) {
if(Keyboard.getEventKeyState()){
System.out.println("KEY DOWN!");
moveUp = true;
}
else{
System.out.println("KEY RELEASED!");
moveUp = false;
}
}
//If key down was pressed move down
else if(Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
if(Keyboard.getEventKeyState()){
System.out.println("KEY DOWN!");
moveDown = true;
}
else{
System.out.println("KEY RELEASED!");
moveDown = false;
}
}
if(moveUp == true){
player.playerMovingUp();
}
if(moveDown == true){
player.playerMovingDown();
}
}
我的代码仍然存在同样的问题,我开始认为它的 Keyboard.next() 阻止了我按住按钮并且玩家仍然移动。