Jump to content
  • Advertisement
Sign in to follow this  
MarlboroKing

[Java] LibGDX GestureDetector - Calling Zoom and Pinch simultaneously

This topic is 999 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In LibGDX, inheriting the GestureDetector class and implementing in to the InputMultiplexer, I am able to pan(move), zoom and pinch(zoom out) my mobile screen in my game (sort of, neither works too well!). The problem I'm facing is when I pinch or zoom, it'll call both Override methods "zoom" and "pinch", to be more precise it'll call "pinch" and then "zoom" directly right after each other.

 

I've read through the LibGDX documentation and spent hours on Google, have not really found a problem similar to mine. Did I miss a method or member? Here's some rough code;

public class GameWorld implements GestureListener, InputProcessor
{
    .....

    public GameWorld()
    {
        ....

        InputMultiplexer im = new InputMultiplexer();
        GestureDetector gd = new GestureDetector(this);
        im.addProcessor(gd);
        im.addProcessor(this);

        Gdx.input.setInputProcessor(im);

        ....
    }

    @Override
    public boolean zoom(float initialDistance, float distance)
    {
        m_Camera.OnZoom(initialDistance, distance);
        return false;
    }

    @Override
    public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2,
            Vector2 pointer1, Vector2 pointer2)
    {
        m_Camera.OnPinch(initialPointer1, initialPointer2, pointer1, pointer2);
        return false;
    }
}

Share this post


Link to post
Share on other sites
Advertisement
Usually you need to write some code that filters out all input and turns it into proper events. In games requiring certifications (like console games) you need to certify the game can always handle contradictory input, like pushing up and down simultaneously, left and right, ok and cancel, etc.

As a safe method you can have an active input state, events trigger the state, and they get set/cleared using an if/else tree. So: if(up) {} else if (down) { } else if (left) { } else if right { } else if (zoom) { } else if (pinch) { } ...

There are other alternatives that stick with event-based processing of input, but this kind of tree is the most direct and easy to program in my view.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!