简体   繁体   English

libGDX - 通过拖动鼠标滚动背景

[英]libGDX - Scrolling background by dragging mouse

I'm trying to make a mouse-scrollable background using libGDX. 我正在尝试使用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? InputProcessor是实现此目的的唯一方法还是更简单的方法? If so, do you know any tutorials about using the mouseDrag-method in InputProcessor? 如果是这样,你知道在InputProcessor中使用mouseDrag方法的任何教程吗? I'm just a noob with libGDX, so if possible write specific replies please. 我只是一个使用libGDX的菜鸟,所以请尽可能写具体的回复。

Use a gesture listener 使用手势监听器

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

pan: A user drags a finger across the screen. pan:用户在屏幕上拖动手指。 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. 用于在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. 阅读文档中的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM