Jinput is awsome, I want it's babies, but a slight issue ....

I tried using it on this simple code, and JInput makes the controller automatically go up and 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();
    }
}

Way to make friends and influence people! :slight_smile:

The problem could be in Slick also?

Kev

But Slick is too awesome to have problems ;D

so… it had been mentioned in this forum that some controllers have an initial (non zero) value. Once you move them once, they work properly.

So… maybe as an initial step:

  1. iterate over all controllers
  2. assume nobody is touching any controllers
  3. record the current values

And for the game-loop:

  1. check to see the current value of each controller
  2. if it’s NOT the same as the initial value, START handling the input events

bump

riven, why did you bump 30 seconds(literaly) after your last post?

Because CyanPrime is bumping his threads all the time, which is utterly useless and annoying.

If I check to make sure they’re not going up and left before I do anything they won’t be able to go up and left x_x

Read it again. :slight_smile:

Without capitals, there would have been no hope!

Some controllers seem to have non zero values until the device is moved. Not all. But some. I have no idea why. What device is showing this issue to you?.

As Riven suggested, you can work around the OS wierdness by assuming the first polled value is not always right, and wait for a controller to change before paying it any attention. I’ve not yet seen any mice or keyboards do this, only game controllers, so that should make life easier.

You could also try using the newer event based interface instead of the old one, I have no idea if that will help as none of my devices show the problem.

HTH

Endolf