LibGdx imput processing

Hi. My name is Jaffar and I am trying to develop a game with LibGdx. I have almost completed the framework for my game, but I am stumped by these two errors in my KeyboardController class. First the code.

package jaffar.pathwaytozorca.game.controller;

import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.math.Vector2;

public class KeyboardController implements InputProcessor {
	public boolean left,right,up,down;
	public boolean isMouse1Down, isMouse2Down,isMouse3Down;
	public boolean isDragged;
	public Vector2 mouseLocation = new Vector2(0,0);

	@Override
	public boolean keyDown(int keycode) {
		boolean keyProcessed = false;
		switch (keycode) // switch code base on the variable keycode
        {
	        case Keys.LEFT:  	// if keycode is the same as Keys.LEFT a.k.a 21
	            left = true;	// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.RIGHT: 	// if keycode is the same as Keys.LEFT a.k.a 22
	            right = true;	// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.UP: 		// if keycode is the same as Keys.LEFT a.k.a 19
	            up = true;		// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.DOWN: 	// if keycode is the same as Keys.LEFT a.k.a 20
	            down = true;	// do this
	            keyProcessed = true;	// we have reacted to a keypress
        }
		return keyProcessed;	//  return our peyProcessed flag
	}
	@Override
	public boolean keyUp(int keycode) {
		boolean keyProcessed = false;
		switch (keycode) // switch code base on the variable keycode
        {
	        case Keys.LEFT:  	// if keycode is the same as Keys.LEFT a.k.a 21
	            left = false;	// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.RIGHT: 	// if keycode is the same as Keys.LEFT a.k.a 22
	            right = false;	// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.UP: 		// if keycode is the same as Keys.LEFT a.k.a 19
	            up = false;		// do this
	            keyProcessed = true;	// we have reacted to a keypress 
	            break;
	        case Keys.DOWN: 	// if keycode is the same as Keys.LEFT a.k.a 20
	            down = false;	// do this
	            keyProcessed = true;	// we have reacted to a keypress
        }
		return keyProcessed;	//  return our peyProcessed flag
	}
	@Override
	public boolean keyTyped(char character) {
		return false;
	}
	@Override
	public boolean touchDown(int screenX, int screenY, int pointer, int button) {
		if(button == 0){
			isMouse1Down = true;
		}else if(button == 1){
			isMouse2Down = true;
		}else if(button == 2){
			isMouse3Down = true;
		}
		mouseLocation.x = screenX;
		mouseLocation.y = screenY;
		return false;
	}

	@Override
	public boolean touchUp(int screenX, int screenY, int pointer, int button) {
		isDragged = false;
		//System.out.println(button);
		if(button == 0){
			isMouse1Down = false;
		}else if(button == 1){
			isMouse2Down = false;
		}else if(button == 2){
			isMouse3Down = false;
		}
		mouseLocation.x = screenX;
		mouseLocation.y = screenY;
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDragged(int screenX, int screenY, int pointer) {
		isDragged = true;
		mouseLocation.x = screenX;
		mouseLocation.y = screenY;
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean mouseMoved(int screenX, int screenY) {
		mouseLocation.x = screenX;
		mouseLocation.y = screenY;
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public boolean scrolled(int amount) {
		return false;
	}
}

Now for the two errors.

  • KeyboardController is not abstract and does not override abstract method scrolled(float,float) in InputProcessor
  • method does not override or implement a method from a supertype. I’m sorry if I can’t format my mail, but I am a blind computer user, and don’t know if my formatting will improve my post or worsen it, so please accept my post as it is. Cheers!
1 Like

Your errors are essentially complaining that you’re missing a required method, and you have an extra method that doesn’t override anything. I believe this is because of your scrolled function, which currently takes a single int amount parameter.

If I look at the InputProcessor interface, its scrolled function takes two float parameters, not a single int amount parameter.

So your code should probably look something like this:

@Override
public boolean scrolled (float amountX, float amountY) {
  return false;
}

Hope that helps!