I have been trying all sorts of ways to get an actor to rotate by clicking-&-dragging on them, with their rotation stopping when the mouse button is released. I can get the actor to rotate following the mouse movement without mouse clicks, but can't get this to only happen when the mouse button is held down - it rotates immediately to the position the mouse was clicked at and stays there until the next click.
Here is my code at the moment.
public class Mirror extends Actor
{
public int state = 0;
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (Greenfoot.mousePressed(this)) {
state = 1;
}
else {
state = 0;
}
}
public void rotate()
{
if (state == 1){
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null)
{
setRotation((int)(180*Math.atan2(mouse.getY()-getY(),mouse.getX()-getX())/Math.PI));
}
}
}
}
Any help would be appreciated!
