February 22, 20169 yr How can I with the API determine what Position I'm hovering at. The same as when you use the entity debug option that shows which tile coordinates your hovering on. It's probably something simple but I haven't found anything useful in the API.
February 22, 20169 yr Entity hover debug shows you which tile you are hovering over if thats what you need.
February 22, 20169 yr Author Entity hover debug shows you which tile you are hovering over if thats what you need. That's exactly what I need but I need it in code. Maybe this example will be more clear: void mouseMoved(MouseEvent e) { Tile tile = new Tile(mouseX, mouseY); log(tile.getPosition()); } This obvious doesn't work, I'm after how I would get this working within osbot Edited February 22, 20169 yr by lisabe96
February 22, 20169 yr That's exactly what I need but I need it in code. Maybe this example will be more clear: void mouseMoved(MouseEvent e) { Tile tile = new Tile(mouseX, mouseY); log(tile.getPosition()); } This obvious doesn't work, I'm after how I would get this working within osbot Not 100% since im not where I can freely test. The solution might be mouse().getArea(); As I said I recall doing this at one point in scripting but I'd have to test it.
February 22, 20169 yr Perhaps you can do something like: for each tile in myplayer.getArea(radius): if tile.polygon contains (mx, my): return tilenot the most efficient solution tho
February 22, 20169 yr Author Perhaps you can do something like: for each tile in myplayer.getArea(radius): if tile.polygon contains (mx, my): return tile not the most efficient solution tho I hope to find something more efficient, but I'll give it a try if I can't figure out anything else Not 100% since im not where I can freely test. The solution might be mouse().getArea(); As I said I recall doing this at one point in scripting but I'd have to test it. This would return java.awt.geom.Area
February 22, 20169 yr I hope to find something more efficient, but I'll give it a try if I can't figure out anything else This would return java.awt.geom.Area I briefly looked at org.osbot.core.debug.HoverDebug and I think it does the same thing, looping through every tile but it compares points in a polygon.
February 22, 20169 yr Author http://osbot.org/forum/topic/66742-getting-position/ Thanks! This should be enough information to get it working
February 22, 20169 yr Author Got it working It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously. But it works. private List<Position> tiles = new ArrayList<>(); @Override public void mouseDragged(MouseEvent e) { handle(e); } @Override public void mouseClicked(MouseEvent e) { handle(e); } private void handle(MouseEvent e) { log(e.getX() + ", " + e.getY()); Position pos = getPosition(e.getPoint()); if (exists(pos)) { tiles.remove(pos); return; } tiles.add(pos); } @Override public void onPaint(Graphics2D graphics) { Graphics2D g = (Graphics2D) graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); g.setColor(Color.GREEN); if (!tiles.isEmpty()) { for (Position t : tiles) { if (t.isVisible(getBot())) { g.draw(t.getPolygon(getBot()).getBounds()); } } } } private Position getPosition(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, getMap().getPlane()); if(pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) { return pos; } } } return null; } private boolean exists(Position pos) { if (!tiles.isEmpty()) { for (Position tile : tiles) { if (tile.equals(pos)) { return true; } } } return false; }
February 22, 20169 yr Got it working It doesn't look good when the camera is tilted as it draws the screen and not the game world obviously. But it works. private List<Position> tiles = new ArrayList<>(); @Override public void mouseDragged(MouseEvent e) { handle(e); } @Override public void mouseClicked(MouseEvent e) { handle(e); } private void handle(MouseEvent e) { log(e.getX() + ", " + e.getY()); Position pos = getPosition(e.getPoint()); if (exists(pos)) { tiles.remove(pos); return; } tiles.add(pos); } @Override public void onPaint(Graphics2D graphics) { Graphics2D g = (Graphics2D) graphics; g.setRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF)); g.setColor(Color.GREEN); if (!tiles.isEmpty()) { for (Position t : tiles) { if (t.isVisible(getBot())) { g.draw(t.getPolygon(getBot()).getBounds()); } } } } private Position getPosition(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, getMap().getPlane()); if(pos.isVisible(getBot()) && pos.getPolygon(getBot()).contains(mousePosition)) { return pos; } } } return null; } private boolean exists(Position pos) { if (!tiles.isEmpty()) { for (Position tile : tiles) { if (tile.equals(pos)) { return true; } } } return false; } Try doing this instead: g.drawPolygon(t.getPolygon(getBot()));
February 22, 20169 yr Author Try doing this instead: g.drawPolygon(t.getPolygon(getBot())); Exactly what I wanted! Thanks a bunch
February 23, 20169 yr I'm not sure drawPolygon will work if the position's Z coordinate is not 0 (could be wrong). If this is the case you could use: Polygon p = position.getPolygon(getBot(), myPosition().getZ()); if(p != null) g2d.draw(p); Which I can confirm DOES work on with all planes. Cheers
February 23, 20169 yr Author I'm not sure drawPolygon will work if the position's Z coordinate is not 0 (could be wrong). If this is the case you could use: Polygon p = position.getPolygon(getBot(), myPosition().getZ()); if(p != null) g2d.draw(p); Which I can confirm DOES work on with all planes. Cheers Thanks, will use. Better avoid possible problems
Create an account or sign in to comment