VVahla
VVahla

Reputation: 95

libGDX - Scrolling background by dragging mouse

I'm trying to make a mouse-scrollable background using libGDX. I've already made the background to loop infinitely, but I have no idea how to make it to scroll by dragging the mouse. Is the InputProcessor the only way to make this or is there an easier way? If so, do you know any tutorials about using the mouseDrag-method in InputProcessor? I'm just a noob with libGDX, so if possible write specific replies please.

Upvotes: 1

Views: 1424

Answers (1)

Boldijar Paul
Boldijar Paul

Reputation: 5495

Use a gesture listener

https://github.com/libgdx/libgdx/wiki/Gesture-detection

pan: A user drags a finger across the screen. The detector will report the current touch coordinates as well as the delta between the current and previous touch positions. Useful to implement camera panning in 2D.

@Override
    public boolean pan(float x, float y, float deltaX, float deltaY) {
        camera.position.x += deltaX;
        camera.update();
        return false;
    }

With this code you are going to move your camera whenever you are dragging your mouse (finger on devices)

Read the link from the documentation.

Upvotes: 3

Related Questions