The getButton() method of MouseInfo only works if the mouse is moving and it's seriously creating a problem for in scenario dragging of objects in my game. How do I make sure the object isn't let go when the mouse stops?
Here's my code:
import greenfoot.*;
import java.awt.Color;
public class Mouse extends Actor
{
Actor light=null;
public Mouse(){
GreenfootImage image = new GreenfootImage(1,1);
image.setColor(Color.WHITE);
image.fill();
setImage(image);
}
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse==null)return;
setLocation(mouse.getX(),mouse.getY());
if (light==null){
light = getOneObjectAtOffset(0,0,Light.class);
}
if (light!=null){
if (mouse.getButton()==1){
light.setLocation(getX(),getY());
}else{
light=null;
}
}
}
}
