Jump to content

Mouse Position <-> Ingame Position


Recommended Posts

Posted (edited)
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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