[LibGDX] Mouse scrolling, Input Processor? [Solved]

   I Google and Googled and all I could find is that I need to make my own class that implements Input Processor since that had a scrolling method. Now I did that and have a bunch of methods for handling input, but I have no idea what I'm doing with this whatsoever. What I'm trying to make is for my game to zoom in when the mouse wheel goes forward, and zoom out when the mouse wheel goes backwards. I already created an instance of my processor and set it as the input processor.

Method From my class that implements input processor (Which I have no idea how to use)


public boolean scrolled(int amount) {
		return false;
		
		}

From my other class which is supposed to check if the mouse wheel is used. The code here is just testing because I have no idea how this method works:


if(Gdx.input.getInputProcessor().scrolled(1)){
			camera.zoom += .05f;
			System.out.println("Scrolled forward.");
		}

According to Javadocs, you have your central input processor implementation with the scrolled method, and you use that ‘amount’ parameter (1 or -1) to know the scroll direction. InputProcessor’s scrolled method is just triggered and input is handled when it happens. You don’t need to use it in an if statement.

Ah, thank you very much! ;D

For those of you who in the future who read this and are confused on how this works. Basically, what I did was pass an instance of the class that had the camera I wanted to zoom to my Input Processor Class. And then from there is where I did the logic.

Example:

public class InputCore implements InputProcessor {

	GameScreen screen;
	
	public InputCore(GameScreen screen){
		this.screen = screen;
	}
	
// I deleted useless methods for the sake of keeping this short.


	@Override
	public boolean scrolled(int amount) {
		
		if(amount == 1){
			screen.camera.zoom += .2f;
		}
		else if(amount == -1){
			screen.camera.zoom -= .2f;
		}
		
		return false;
		
			}
		}

For a quicker scrolled method you could do:

screen.camera.zoom += amount * 0.2f;

since the amount will only either be 1 or -1 :stuck_out_tongue:

Very true, thank you! I can’t believe I managed to forget basic multiplication, and to think I used that same sort of thing in a pong game the other day.