I wanted the object of this class to start following the cursor when the you click with the mouse anywhere and stop when you release it. Though, for some reason the loop doesn´t end when released and also only puts the object where the cursor was when clicked and never follows it. If anyone knows, what the problem is, please respond.
Thank you in advance!
1 2 3 4 5 6 7 8 9 10 11 12 13 | public void act() { if (Greenfoot.mousePressed( null )) { World world = (World) getWorld(); MouseInfo mouse = Greenfoot.getMouseInfo(); while (!Greenfoot.mouseClicked( null )) { setLocation(mouse.getX(), mouse.getY()); world.repaint(); } } } |