0
\$\begingroup\$

TL;DR

How can I move window with mouse without tide effect.

Long Version

So when I tried to move my game window via InputListener(just to test if it would work). I got some strange result. The window goes back and forth between last two locations when mouse drags and while button is held.

Game Part

Gdx.input.setInputProcessor(new InputAdapter() {
    int b;
    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        b = button;
        // TODO Auto-generated method stub
        Rectangle.tmp.set(0, 0, 100, 100);
        if (Rectangle.tmp.contains(screenX, screenY)) {
            lastx = screenX;
            lasty = screenY;
            System.err.println("Touch ( " + screenX + " , " + screenY + " )");
        }

        return true;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        if (lastx != null && tr != null) {
            tr.translate(screenX - lastx, screenY - lasty);
            System.err.println("Drag  ( " + lastx + " - " + screenX + " , " + lasty + " - " + screenY + " )");
            lastx = screenX;
            lasty = screenY;
        }
        return true;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        lastx = null;
        lasty = null;
        System.err.println("Up ( " + lastx + " , " + lasty + " )");
        return true;
    }
});

DesktopLauncher Part

Game.tr = new Translator() {

    @Override
    public boolean translate(int x, int y) {
        Display.setLocation(Display.getX() + x, Display.getY() + y);
        return true;
    }
};

PS: What I try&tried to make may look stupid.

Edit: Actually I noticed that window moves less than actual mouse movement. Edit2: When I move the movement code to touchUp I get exact result as movement.

\$\endgroup\$
4
  • \$\begingroup\$ What exactly are you trying to do here? Move the game window? You can already do this by pulling the window normally as with any other window. \$\endgroup\$
    – Charanor
    Jan 31 '17 at 23:54
  • \$\begingroup\$ Yes that is why I said "what I try to make may look stupid.". The game window freezes when you try to move and I want to make a game where you move the window to translate camera so you play the game in your desktop actually. So I told myself if the whole thing is caused by window drag maybe I if I handle it would not cause freeze. \$\endgroup\$ Feb 1 '17 at 8:30
  • \$\begingroup\$ I see. I don't know if something like this would be possible since things like this is probably tied to your operating system, not Libgdx or Java. Someone correct me if I'm wrong. \$\endgroup\$
    – Charanor
    Feb 1 '17 at 8:39
  • \$\begingroup\$ actually if there is a way to get desktop coordinate system I would be able to move window accordingly. \$\endgroup\$ Feb 1 '17 at 10:03
0
\$\begingroup\$

So I changed my code as this.

Game Code

    Gdx.input.setInputProcessor(new InputAdapter() {
        int offsetX;
        int offsetY;
        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            offsetX = screenX;
            offsetY = screenY;
            System.err.println("Touch (" + screenX + " , " + screenY + ")");
            return true;
        }

        @Override
        public boolean touchDragged(int screenX, int screenY, int pointer) {
            tr.translate(offsetX, offsetY);
            return true;
        }

        @Override
        public boolean touchUp(int screenX, int screenY, int pointer, int button) {
            offsetX = 0;
            offsetY = 0;
            return true;
        }
    });

Desktop Launcher Code

    MyGame.tr = new Translator() {

        @Override
        public boolean translate(int x, int y) {
            // WINDOW_HEIGHT is a static variable on launcher code. In my case that would be enough but there is Display.getHeight function if someone needs.
            Display.setLocation(Display.getX() + (Mouse.getX() - x), Display.getY() + (WINDOW_HEIGHT- Mouse.getY() - y));
            return true;
        }
    };

So instead of trying to use touchDragged to move window. I cache the relative location of my window where the mouse pressed. And move the window to catch that point. this may or may not change the fact that game would pause rendering or not cause I currently do not have anything to render.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .