Jump to content

Mouse Position <-> Ingame Position


_ynx

Recommended Posts

15 minutes ago, _ynx said:

I mean during runtime. i need to dynamically get what ingame position the mouse is pointed over and vice versa

You can do something like this to get the Position under mouse:

public final Optional<Position> getPositionUnderMouse(final Point mousePosition) {
    for (int x = 0; x < 104; x++) {
        for (int y = 0; y < 104; y++) {
            Position pos = new Position(getMap().getBaseX() + x, getMap().getBaseY() + y, myPosition().getZ());
            if (pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) {
                return Optional.of(pos);
            }
        }
    }
    return Optional.empty();
}

 

Usage:

Position position = getPositionUnderMouse(getMouse().getPosition());

 

You cant really convert a Position to a mouse point, but you can get it's on screen Polygon:

Polygon polygon = position.getPolygon(getBot());

 

Edited by Explv
  • Like 5
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...