gpt4 book ai didi

java - Jinput init 的 Controller up 和 left 为 true

转载 作者:行者123 更新时间:2023-12-01 05:59:00 26 4
gpt4 key购买 nike

我尝试在这个简单的代码上使用它,JInput 使 Controller 自动向上和向左!看起来 input.isControllerUp(Input.ANY_CONTROLLER) 开始是正确的!我该如何解决这个问题?

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();
}
}

最佳答案

Input 不是 JInput 的类,它来自 slick 库。我直接使用JInput,没有出现类似问题。

关于java - Jinput init 的 Controller up 和 left 为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1792364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com