简体   繁体   中英

Camera Scrolling libGDX

For some reason, when i scroll my screen, it only saves the touch coordinates when i first touch my screen and starts saving (0,0) in lastTouch while dragging. I'm trying to move my camera by scrolling by saving this value in my GameWorld class which will be called by GameRender where my main camera is. I have also tried with Vector3, and just float but still no luck..

Please help!

Vector2 lastTouch = new Vector2();

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
    // TODO Auto-generated method stub

        lastTouch.set(screenX, screenY);

    return true;
}

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
    // TODO Auto-generated method stub

    System.out.println("TouchDragged lasty : " + lastTouch.y + "y :" + screenY);
    int dis = (int) lastTouch.y - screenY;
    System.out.println(dis);
    world.setDis(dis);

    return true;
}

Ok. SOLUTION: what happened was that I forgot that if I scroll down, the input value of y would also need to change since the position of y of camera's perspective has changed. What I did was that I've added the half value of camera's position in the input for scrolling. It's still kinda buggy but it's doing its job! leave comments and I will help out as much as I can =]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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