0
\$\begingroup\$

I'm try to make offset x and offset y move correspond with mouse drag movement I tested it. Its work but after I released the mouse and do it again the offset will reset to 0, 0

I tried to fix it by adding old offset x, y and the result is the offset will keep increasing.

Here my code :

public void updateOffset() {
    if(Game.getMouseInput().mouseState == MouseEvent.BUTTON1 && !closeOrigin) {
        ox = Game.getMouseInput().x;
        oy = Game.getMouseInput().y;
        ex = Game.getMouseInput().x;
        ey = Game.getMouseInput().y;
        closeOrigin = true;
    } 

    if(Game.getMouseInput().drag) {
        ex = Game.getMouseInput().x;
        ey = Game.getMouseInput().y;
    }

    if(ex - ox == 0 && ey - oy == 0)
        return;

    offsetX = ex - ox;
    offsetY = ey - oy;

    if(Game.getMouseInput().mouseState == MouseEvent.NOBUTTON && closeOrigin) {
        offsetX = ex - ox;
        offsetY = ey - oy;
        closeOrigin = false;
    }
}

And this code is called every frames

\$\endgroup\$
  • \$\begingroup\$ It's a bit unclear what it is you're trying to achieve and what you need help with. Can you try explaining a bit more and maybe add an image and/or an animation on what it is you're trying to achieve? \$\endgroup\$ – Daniel_1985 Apr 16 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.