Hi!
I made the below code in an actor class.
First the code worked as expected, the object was possible to drag on the left side of the world.
Then I started getting nullpointer exceptions and the code didn't do anything any more.
Why do I get the exception?
Thanks!
Karl
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class ButtonDestroyer extends Actor
{
public void act()
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getX()< 600)
{
mouseDragging();
}
}
private void mouseDragging() {
if (Greenfoot.mouseDragged(this)) {
MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation(mouse.getX(), mouse.getY());
}
}
}