I'm trying to make it so when I left click, it places ONE planet at the cursor, but instead, it creates planets for as long as you hold the left click down. I tried to use sort of a "flip-switch" system.
Help would be much appreciated!
private void clickAndGen() {
MouseInfo mouse = Greenfoot.getMouseInfo();
if(mouse != null) {
int button = mouse.getButton();
boolean isDown = false;
if(button == 1 && !isDown)
{
int msx = mouse.getX();
int msy = mouse.getY();
addObject(new Body(false, Greenfoot.getRandomNumber(100)+1, Greenfoot.getRandomNumber(300)+1, new Vector(getRandomNumber(0,360),getRandomNumber(-2,1)), new Color(Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255), Greenfoot.getRandomNumber(255))), msx, msy);
isDown = true;
}
else if(isDown && button != 1) {
isDown = false;
}
}
}
}
