我尝试在此简单代码上使用它,而JInput使控制器自动上下移动!它似乎认为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的类,它来自光滑的库。我直接使用JInput,没有类似问题。

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

10-10 04:26