我試過在這個簡單的代碼上使用它,並且JInput使控制器自動升起和離開! IT看到input.isControllerUp(Input.ANY_CONTROLLER)開始爲真!我怎樣才能解決這個問題?Jinput init的控制器up和left爲真
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class Test1 extends BasicGame{
float x = 300;
float y = 300;
public Test1()
{
super("Controller Test 1");
}
@Override
public void init(GameContainer gc)
throws SlickException {
}
public void updateControler(GameContainer gc){
Input input = gc.getInput();
System.out.println("input.isControllerUp(Input.ANY_CONTROLLER)" + input.isControllerUp(Input.ANY_CONTROLLER));
if(input.isKeyDown(Input.KEY_UP) || input.isControllerUp(Input.ANY_CONTROLLER)) {
y--;
}
else if(input.isKeyDown(Input.KEY_DOWN) || input.isControllerDown(Input.ANY_CONTROLLER)) {
y++;
}
else if(input.isKeyDown(Input.KEY_LEFT) || input.isControllerLeft(Input.ANY_CONTROLLER)) {
x--;
}
else if(input.isKeyDown(Input.KEY_RIGHT) || input.isControllerRight(Input.ANY_CONTROLLER)) {
x++;
}
}
@Override
public void update(GameContainer gc, int delta)
throws SlickException
{;
updateControler(gc);
}
public void render(GameContainer gc, Graphics g)
throws SlickException
{
g.setColor(Color.red);
g.fillRect(x,y,50,50);
}
public static void main(String[] args)
throws SlickException
{
AppGameContainer app =
new AppGameContainer(new Test1());
app.setDisplayMode(800, 600, false);
app.start();
}
}
我也經歷過同樣的事情。實際上,似乎有幾個軸開始按下,而不是方向按鈕。我甚至用兩個不同的控制器試過,得到了相同的結果。 – 2012-01-29 20:35:49