如果有人可以提供帮助,我正在徘徊,基本上我在学习一些输入处理的教程,并且教程要求我创建一个新类并编写这段代码。
package net.pinkeye.JavaGame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.List;
public class InputHandler implements KeyListener{
public InputHandler(Game game) {
game.addKeyListener(this);
}
public class Key {
public boolean pressed = false;
public boolean isPressed(){
return pressed;
}
public void toggle(boolean isPressed) {
pressed = isPressed;
}
}
public Key up = new Key();
public Key down = new Key();
public Key left = new Key();
public Key right = new Key();
public void keyPressed(KeyEvent e) {
toggleKey(e.getKeyCode(),true);
}
public void keyReleased(KeyEvent e) {
toggleKey(e.getKeyCode(),false);
}
public void keyTyped(KeyEvent e) {
}
public void toggle (int keyCode, boolean isPressed) {
if(keyCode == KeyEvent.VK_W){
up.toggle(isPressed);
}
if(keyCode == KeyEvent.VK_S){
down.toggle(isPressed);
}
if(keyCode == KeyEvent.VK_A){
left.toggle(isPressed);
}
if(keyCode == KeyEvent.VK_D){
right.toggle(isPressed);
}
}
}
但是它在哪里说
public void keyPressed(KeyEvent e) {
toggleKey(e.getKeyCode(),true);
}
public void keyReleased(KeyEvent e) {
toggleKey(e.getKeyCode(),false);
}
eclipse 告诉我 InputHandler 类型的方法 toggleKey(int, boolean) 未定义
我按照 wrd 这个教程的单词进行了多次检查,但我找不到我的错误。
任何帮助都会很棒
顺便说一句,如果这有帮助,这里是 tuorial:http ://www.youtube.com/watch?v=Vv7G5GMORE8