0

I have a LibGDX program where I have added a touchpad when the program is being run in Android. The touchpad is working as desired.

I have set it so that if I touch an area of the screen that is not the touchpad or any UI buttons, it will move the touchpad to that location. That piece is working correctly as well.

However, to use the touchpad after moving it to a new location, I must lift my finger, then put it back down. I can't start dragging to use the touchpad once I put my finger in the new location.

Creating the touchpad is done in a completely standard way:

touchpad = new Touchpad(5, touchpadStyle);

Moving the touchpad is done here:

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    Vector3 vec = new Vector3(screenX, screenY, 0);
    uiStage.getCamera().unproject(vec);
    touchpad.setPosition(vec.x-touchpad.getWidth()/2, vec.y - touchpad.getHeight()/2);
    return false;
}

I was looking at possibly extending the Touchpad class, but I wasn't sure if it would be possible to do that way, and/or if there might be an easier way to do this that I just haven't yet discovered.

Thanks in advance!

Tux
  • 57
  • 1
  • 4
  • I think it would be helpfull to see the part where you handle dragging – Luis Fernando Frontanilla Apr 12 '19 at 10:00
  • I'm using the LibGDX Touchpad class. Dragging is handled by that. – Tux Apr 13 '19 at 13:06
  • Why do you move the touchpad? It sounds like you want the whole screen to be a touchpad. Possibly you want to do something relative to the first touch coordinates. Rather just cache touch down coords then do the rest of your operations offset to that. – Laurence Apr 14 '19 at 15:19

1 Answers1

0
stage.addListener(new InputListener()
        {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
            {
                System.out.println("event = " + event + ", x = " + x + ", y = " + y + ", pointer = " + pointer + ", button = " + button);
                if (!touchpad.isTouched())
                {
                    touchpad.setPosition(x, y, Align.center);
                    touchpad.fire(event);
                }
                return super.touchDown(event, x, y, pointer, button);
            }
        });