Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I'm trying to create a input class that implements a InputHandler & GestureListener in order to support both Android & Desktop. The problem is that not all the methods are being called properly.

Here is the input class definition & a couple of the methods:

public class InputHandler implements GestureListener, InputProcessor{  
...
public InputHandler(OrthographicCamera camera, Map m, Player play, Vector2 maxPos) {  
...
@Override
public boolean zoom(float originalDistance, float currentDistance) {
    //this.zoom = true;
    this.zoomRatio = originalDistance / currentDistance;
    cam.zoom = cam.zoom * zoomRatio;
    Gdx.app.log("GestureDetector", "Zoom - ratio: " + zoomRatio);
    return true;
}

@Override
public boolean touchDown(int x, int y, int pointerNum, int button) {
    booleanConditions[TOUCH_EVENT] = true;
    this.inputButton = button;
    this.inputFingerNum = pointerNum;   
    this.lastTouchEventLoc.set(x,y);
    this.currentCursorPos.set(x,y);

    if(pointerNum == 1) {
        //this.fingerOne = true;
        this.fOnePosition.set(x, y);
    }
    else if(pointerNum == 2) {
        //this.fingerTwo = true;
        this.fTwoPosition.set(x,y);
    }       

    Gdx.app.log("GestureDetector", "touch down at " + x + ", " + y + ", pointer: " + pointerNum);       
    return true;
}

The touchDown event always occurs but I can never trigger Zoom (or pan among others...). The following is where I register and create the input handler in the "Game Screen".

public class GameScreen implements Screen {  
...  
   this.inputHandler = new InputHandler(this.cam, this.map, this.player, this.map.maxCamPos);
   Gdx.input.setInputProcessor(this.inputHandler);  

Anyone have any ideas why zoom, pan, etc... are not triggering?

Thanks!

share|improve this question
Any ideas why it's not working? What have you tried? – Anko Dec 15 '12 at 11:47
Have you tried changing if ... else if ... to simply if .... if .... This is in your touchDown event. – Brendan May 14 at 21:31

1 Answer

After doing some investigation I switched the way I setup the project. I now have a controller class following a similar design as: http://www.badlogicgames.com/wordpress/?p=2668 where Mario describes his game architecture. Go to the controller section to see how he implemented his ControllerManager as mine is a near clone.

I use the controller in the following way:

public class GameScreen implements Screen {
...
    private ControllerManager controllerManager;
    ...
    public void show() {
        InputMultiplexer inputMulti = new InputMultiplexer();
        this.controllerManager = new ControllerManager(inputMulti);

        if(Gdx.app.getType() == ApplicationType.Desktop) {
            DeskController deskController = new DeskController(this.cam, this.map, this.player, this.map.maxCamPos);
            this.controllerManager.addController(deskController);
        }
        else {
            AndroidController androidController = new AndroidController(this.cam, this.map, this.player, this.map.maxCamPos);
            this.controllerManager.addController(androidController);
        }
        Gdx.input.setInputProcessor(controllerManager.getInputMultiplexer());

My deskController class is a standard inputProcessor, and androidController is a Gesture Detector.

Hope this helps someone else who is struggling with getting inputs from multiple devices.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.