Cloxygen Posted June 1, 2017 Share Posted June 1, 2017 (edited) For some reason the paint for bounding box is off. I used the same code for detecting clicks inside the bounding box and that works in the correct positions, but the paint is offset from the actual. Would anyone know why? Edit: They seem to be lining up diagonally Edited June 1, 2017 by Cloxygen Quote Link to comment Share on other sites More sharing options...
Vilius Posted June 1, 2017 Share Posted June 1, 2017 I mean, it would be great if you would show us your code. 1 Quote Link to comment Share on other sites More sharing options...
Cloxygen Posted June 1, 2017 Author Share Posted June 1, 2017 1 minute ago, Vilius said: I mean, it would be great if you would show us your code. This Works: private MouseListener clickListener = new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (startButton.contains(e.getPoint())) { started = true; } else if (!started) { for (int i = 0; i < selectedTrees.size(); i++) { if (selectedTrees.get(i).getModel().getBoundingBox(selectedTrees.get(i).getGridX(), selectedTrees.get(i).getGridY(), selectedTrees.get(i).getZ()).contains(e.getPoint())) { selectedTrees.remove(selectedTrees.get(i)); return; } } for (int i = 0; i < nearbyTrees.size(); i++) { if (nearbyTrees.get(i).getModel().getBoundingBox(nearbyTrees.get(i).getGridX(), nearbyTrees.get(i).getGridY(), nearbyTrees.get(i).getZ()).contains(e.getPoint())) { selectedTrees.add(nearbyTrees.get(i)); return; } } } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }; This Doesn't: public void onPaint(final Graphics2D g) { if (choppingArea.contains(myPlayer())) { //Paints nearby trees if (!started) { g.setColor(Color.WHITE); g.drawString("PLEASE SELECT ORE.", 195, 305); g.setColor(Color.GRAY); for (int i = 0; i < nearbyTrees.size(); i++) { checkTree = nearbyTrees.get(i); model = checkTree.getModel(); g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); } g.drawImage(startButtonimg, 645, 452, null); } g.setColor(Color.WHITE); for(int i = 0;i < selectedTrees.size();i++){ if(selectedTrees.get(i) != null){ checkTree = selectedTrees.get(i); model = checkTree.getModel(); g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); } } } Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted June 1, 2017 Share Posted June 1, 2017 35 minutes ago, Cloxygen said: This Works: private MouseListener clickListener = new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (startButton.contains(e.getPoint())) { started = true; } else if (!started) { for (int i = 0; i < selectedTrees.size(); i++) { if (selectedTrees.get(i).getModel().getBoundingBox(selectedTrees.get(i).getGridX(), selectedTrees.get(i).getGridY(), selectedTrees.get(i).getZ()).contains(e.getPoint())) { selectedTrees.remove(selectedTrees.get(i)); return; } } for (int i = 0; i < nearbyTrees.size(); i++) { if (nearbyTrees.get(i).getModel().getBoundingBox(nearbyTrees.get(i).getGridX(), nearbyTrees.get(i).getGridY(), nearbyTrees.get(i).getZ()).contains(e.getPoint())) { selectedTrees.add(nearbyTrees.get(i)); return; } } } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }; This Doesn't: public void onPaint(final Graphics2D g) { if (choppingArea.contains(myPlayer())) { //Paints nearby trees if (!started) { g.setColor(Color.WHITE); g.drawString("PLEASE SELECT ORE.", 195, 305); g.setColor(Color.GRAY); for (int i = 0; i < nearbyTrees.size(); i++) { checkTree = nearbyTrees.get(i); model = checkTree.getModel(); g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); } g.drawImage(startButtonimg, 645, 452, null); } g.setColor(Color.WHITE); for(int i = 0;i < selectedTrees.size();i++){ if(selectedTrees.get(i) != null){ checkTree = selectedTrees.get(i); model = checkTree.getModel(); g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); } } } " g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); " You're using #getGridX() twice here in the painting. 2 Quote Link to comment Share on other sites More sharing options...
Cloxygen Posted June 1, 2017 Author Share Posted June 1, 2017 22 minutes ago, Bobrocket said: " g.draw(model.getBoundingBox(checkTree.getGridX(),checkTree.getGridX(),checkTree.getZ())); " You're using #getGridX() twice here in the painting. wow i feel dumb, thanks Quote Link to comment Share on other sites More sharing options...
dmmslaver Posted June 1, 2017 Share Posted June 1, 2017 (edited) 12 hours ago, Cloxygen said: wow i feel dumb, thanks You can see the pattern of that in how the rectangles are drawn all in a "line" kinda. for future reference Also you don't really wanna use a rectangle because of these red areas Edited June 1, 2017 by dmmslaver Quote Link to comment Share on other sites More sharing options...