This site requires JavaScript, please enable it in your browser!
Greenfoot back
doglover555
doglover555 wrote ...

2017/11/30

mouseDragged() help

doglover555 doglover555

2017/11/30

#
I'm trying to make it so that the subclasses of Pet will follow my mouse when I drag it on them. I put super.act(); in the act method of each of the subclasses, but when I run the code it doesn't work. Not sure if I'm missing a step.
public class Pet extends Actor
{
    /**
     * Act - do whatever the Pet wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
       movePet();
    }    
    
    public void movePet()
    {
        if(Greenfoot.mouseDragged(Pet.class))
        {
            setLocation(Greenfoot.getMouseInfo().getX(), Greenfoot.getMouseInfo().getY());
        }
    }
}
Super_Hippo Super_Hippo

2017/11/30

#
The mouseDragged method requires an object, not a class. So for a start, replace 'Pet.class' with 'this'.
You need to login to post a reply.