views:

69

answers:

1

I tried using it on this simple code, and JInput makes the controller automatically go up and left! IT seeems that input.isControllerUp(Input.ANY_CONTROLLER) starts out as true! How can I fix this?

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

Input is not a class of JInput, it comes from the slick library. I am using JInput directly and I have no similar problems.

Vincent